{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": [],
      "gpuType": "T4"
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    },
    "accelerator": "GPU"
  },
  "cells": [
    {
      "cell_type": "code",
      "source": [
        "!pip install --upgrade pip\n"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "27UlIRUJzPRP",
        "outputId": "6978d8e3-3add-4af3-9888-246ad506ab5a"
      },
      "execution_count": 64,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Requirement already satisfied: pip in /usr/local/lib/python3.10/dist-packages (23.1.2)\n",
            "Collecting pip\n",
            "  Downloading pip-24.0-py3-none-any.whl (2.1 MB)\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m2.1/2.1 MB\u001b[0m \u001b[31m5.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25hInstalling collected packages: pip\n",
            "  Attempting uninstall: pip\n",
            "    Found existing installation: pip 23.1.2\n",
            "    Uninstalling pip-23.1.2:\n",
            "      Successfully uninstalled pip-23.1.2\n",
            "Successfully installed pip-24.0\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "!pip install tensorflow-gpu==2.8.0\n"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "HAHa1lc0z0cu",
        "outputId": "b6479eb6-d945-4955-b9f9-782cf9dd8e44"
      },
      "execution_count": 1,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Requirement already satisfied: tensorflow-gpu==2.8.0 in /usr/local/lib/python3.10/dist-packages (2.8.0)\n",
            "Requirement already satisfied: absl-py>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from tensorflow-gpu==2.8.0) (1.4.0)\n",
            "Requirement already satisfied: astunparse>=1.6.0 in /usr/local/lib/python3.10/dist-packages (from tensorflow-gpu==2.8.0) (1.6.3)\n",
            "Requirement already satisfied: flatbuffers>=1.12 in /usr/local/lib/python3.10/dist-packages (from tensorflow-gpu==2.8.0) (24.3.25)\n",
            "Requirement already satisfied: gast>=0.2.1 in /usr/local/lib/python3.10/dist-packages (from tensorflow-gpu==2.8.0) (0.5.4)\n",
            "Requirement already satisfied: google-pasta>=0.1.1 in /usr/local/lib/python3.10/dist-packages (from tensorflow-gpu==2.8.0) (0.2.0)\n",
            "Requirement already satisfied: h5py>=2.9.0 in /usr/local/lib/python3.10/dist-packages (from tensorflow-gpu==2.8.0) (3.9.0)\n",
            "Requirement already satisfied: keras-preprocessing>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from tensorflow-gpu==2.8.0) (1.1.2)\n",
            "Requirement already satisfied: libclang>=9.0.1 in /usr/local/lib/python3.10/dist-packages (from tensorflow-gpu==2.8.0) (18.1.1)\n",
            "Requirement already satisfied: numpy>=1.20 in /usr/local/lib/python3.10/dist-packages (from tensorflow-gpu==2.8.0) (1.25.2)\n",
            "Requirement already satisfied: opt-einsum>=2.3.2 in /usr/local/lib/python3.10/dist-packages (from tensorflow-gpu==2.8.0) (3.3.0)\n",
            "Requirement already satisfied: protobuf>=3.9.2 in /usr/local/lib/python3.10/dist-packages (from tensorflow-gpu==2.8.0) (3.20.3)\n",
            "Requirement already satisfied: setuptools in /usr/local/lib/python3.10/dist-packages (from tensorflow-gpu==2.8.0) (67.7.2)\n",
            "Requirement already satisfied: six>=1.12.0 in /usr/local/lib/python3.10/dist-packages (from tensorflow-gpu==2.8.0) (1.16.0)\n",
            "Requirement already satisfied: termcolor>=1.1.0 in /usr/local/lib/python3.10/dist-packages (from tensorflow-gpu==2.8.0) (2.4.0)\n",
            "Requirement already satisfied: typing-extensions>=3.6.6 in /usr/local/lib/python3.10/dist-packages (from tensorflow-gpu==2.8.0) (4.11.0)\n",
            "Requirement already satisfied: wrapt>=1.11.0 in /usr/local/lib/python3.10/dist-packages (from tensorflow-gpu==2.8.0) (1.14.1)\n",
            "Requirement already satisfied: tensorboard<2.9,>=2.8 in /usr/local/lib/python3.10/dist-packages (from tensorflow-gpu==2.8.0) (2.8.0)\n",
            "Requirement already satisfied: tf-estimator-nightly==2.8.0.dev2021122109 in /usr/local/lib/python3.10/dist-packages (from tensorflow-gpu==2.8.0) (2.8.0.dev2021122109)\n",
            "Requirement already satisfied: keras<2.9,>=2.8.0rc0 in /usr/local/lib/python3.10/dist-packages (from tensorflow-gpu==2.8.0) (2.8.0)\n",
            "Requirement already satisfied: tensorflow-io-gcs-filesystem>=0.23.1 in /usr/local/lib/python3.10/dist-packages (from tensorflow-gpu==2.8.0) (0.36.0)\n",
            "Requirement already satisfied: grpcio<2.0,>=1.24.3 in /usr/local/lib/python3.10/dist-packages (from tensorflow-gpu==2.8.0) (1.62.2)\n",
            "Requirement already satisfied: wheel<1.0,>=0.23.0 in /usr/local/lib/python3.10/dist-packages (from astunparse>=1.6.0->tensorflow-gpu==2.8.0) (0.43.0)\n",
            "Requirement already satisfied: google-auth<3,>=1.6.3 in /usr/local/lib/python3.10/dist-packages (from tensorboard<2.9,>=2.8->tensorflow-gpu==2.8.0) (2.27.0)\n",
            "Requirement already satisfied: google-auth-oauthlib<0.5,>=0.4.1 in /usr/local/lib/python3.10/dist-packages (from tensorboard<2.9,>=2.8->tensorflow-gpu==2.8.0) (0.4.6)\n",
            "Requirement already satisfied: markdown>=2.6.8 in /usr/local/lib/python3.10/dist-packages (from tensorboard<2.9,>=2.8->tensorflow-gpu==2.8.0) (3.6)\n",
            "Requirement already satisfied: requests<3,>=2.21.0 in /usr/local/lib/python3.10/dist-packages (from tensorboard<2.9,>=2.8->tensorflow-gpu==2.8.0) (2.31.0)\n",
            "Requirement already satisfied: tensorboard-data-server<0.7.0,>=0.6.0 in /usr/local/lib/python3.10/dist-packages (from tensorboard<2.9,>=2.8->tensorflow-gpu==2.8.0) (0.6.1)\n",
            "Requirement already satisfied: tensorboard-plugin-wit>=1.6.0 in /usr/local/lib/python3.10/dist-packages (from tensorboard<2.9,>=2.8->tensorflow-gpu==2.8.0) (1.8.1)\n",
            "Requirement already satisfied: werkzeug>=0.11.15 in /usr/local/lib/python3.10/dist-packages (from tensorboard<2.9,>=2.8->tensorflow-gpu==2.8.0) (3.0.2)\n",
            "Requirement already satisfied: cachetools<6.0,>=2.0.0 in /usr/local/lib/python3.10/dist-packages (from google-auth<3,>=1.6.3->tensorboard<2.9,>=2.8->tensorflow-gpu==2.8.0) (5.3.3)\n",
            "Requirement already satisfied: pyasn1-modules>=0.2.1 in /usr/local/lib/python3.10/dist-packages (from google-auth<3,>=1.6.3->tensorboard<2.9,>=2.8->tensorflow-gpu==2.8.0) (0.4.0)\n",
            "Requirement already satisfied: rsa<5,>=3.1.4 in /usr/local/lib/python3.10/dist-packages (from google-auth<3,>=1.6.3->tensorboard<2.9,>=2.8->tensorflow-gpu==2.8.0) (4.9)\n",
            "Requirement already satisfied: requests-oauthlib>=0.7.0 in /usr/local/lib/python3.10/dist-packages (from google-auth-oauthlib<0.5,>=0.4.1->tensorboard<2.9,>=2.8->tensorflow-gpu==2.8.0) (1.3.1)\n",
            "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2.21.0->tensorboard<2.9,>=2.8->tensorflow-gpu==2.8.0) (3.3.2)\n",
            "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2.21.0->tensorboard<2.9,>=2.8->tensorflow-gpu==2.8.0) (3.7)\n",
            "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2.21.0->tensorboard<2.9,>=2.8->tensorflow-gpu==2.8.0) (2.0.7)\n",
            "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests<3,>=2.21.0->tensorboard<2.9,>=2.8->tensorflow-gpu==2.8.0) (2024.2.2)\n",
            "Requirement already satisfied: MarkupSafe>=2.1.1 in /usr/local/lib/python3.10/dist-packages (from werkzeug>=0.11.15->tensorboard<2.9,>=2.8->tensorflow-gpu==2.8.0) (2.1.5)\n",
            "Requirement already satisfied: pyasn1<0.7.0,>=0.4.6 in /usr/local/lib/python3.10/dist-packages (from pyasn1-modules>=0.2.1->google-auth<3,>=1.6.3->tensorboard<2.9,>=2.8->tensorflow-gpu==2.8.0) (0.6.0)\n",
            "Requirement already satisfied: oauthlib>=3.0.0 in /usr/local/lib/python3.10/dist-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib<0.5,>=0.4.1->tensorboard<2.9,>=2.8->tensorflow-gpu==2.8.0) (3.2.2)\n",
            "\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\u001b[0m\u001b[33m\n",
            "\u001b[0m"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "pip install plotly"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "ePfR6sNCGLXx",
        "outputId": "4b6697de-f38a-4586-bec9-5e5ca011fe83"
      },
      "execution_count": 2,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Requirement already satisfied: plotly in /usr/local/lib/python3.10/dist-packages (5.15.0)\n",
            "Requirement already satisfied: tenacity>=6.2.0 in /usr/local/lib/python3.10/dist-packages (from plotly) (8.2.3)\n",
            "Requirement already satisfied: packaging in /usr/local/lib/python3.10/dist-packages (from plotly) (24.0)\n",
            "\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\u001b[0m\u001b[33m\n",
            "\u001b[0m"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "import tensorflow as tf\n",
        "\n",
        "# Check if GPU is available\n",
        "print(\"GPU is\", \"available\" if tf.config.list_physical_devices('GPU') else \"not available\")\n",
        "\n",
        "# Perform a simple computation on GPU\n",
        "with tf.device('/GPU:0'):\n",
        "    a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0])\n",
        "    b = tf.constant([5.0, 4.0, 3.0, 2.0, 1.0])\n",
        "    c = a + b\n",
        "\n",
        "# Print the result\n",
        "print(c)\n"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "nL0soqObzRrV",
        "outputId": "776300b2-10a7-4fda-82e6-c777eda69918"
      },
      "execution_count": 4,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "GPU is not available\n",
            "tf.Tensor([6. 6. 6. 6. 6.], shape=(5,), dtype=float32)\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "# Import Libraries"
      ],
      "metadata": {
        "id": "-itFdL7JSRE8"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "import os\n",
        "import random\n",
        "import shutil\n",
        "import zipfile\n",
        "import operator\n",
        "import numpy as np\n",
        "import tensorflow as tf\n",
        "import plotly.graph_objects as go\n",
        "from plotly.subplots import make_subplots\n",
        "\n",
        "from sklearn.model_selection import train_test_split\n",
        "from tensorflow.keras.applications import ResNet50\n",
        "from tensorflow.keras.models import Sequential\n",
        "from tensorflow.keras.optimizers import Adam\n",
        "from tensorflow.keras.preprocessing.image import ImageDataGenerator\n",
        "from tensorflow.keras.layers import Input, BatchNormalization, Activation, Add\n",
        "from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense, Dropout, GlobalAveragePooling2D"
      ],
      "metadata": {
        "id": "voz8P6w99sjQ"
      },
      "execution_count": 1,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "print(\"TensorFlow version:\", tf.__version__)\n",
        "\n",
        "# Check if GPU is available\n",
        "if tf.test.gpu_device_name():\n",
        "    print('GPU:', tf.test.gpu_device_name())\n",
        "else:\n",
        "    print(\"No GPU available\")\n",
        "\n",
        "# Check if TPU is available\n",
        "try:\n",
        "    resolver = tf.distribute.cluster_resolver.TPUClusterResolver()\n",
        "    tf.config.experimental_connect_to_cluster(resolver)\n",
        "    tf.tpu.experimental.initialize_tpu_system(resolver)\n",
        "    print(\"TPU:\", resolver.master())\n",
        "except Exception as e:\n",
        "    print(\"No TPU available:\", e)\n"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "PgJM3ms7GEYX",
        "outputId": "e1be3dcc-9a17-4a16-eea0-bb61d72d5b1a"
      },
      "execution_count": 2,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "TensorFlow version: 2.15.0\n",
            "GPU: /device:GPU:0\n",
            "No TPU available: Please provide a TPU Name to connect to.\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "# Normalize and Visualize Dataset"
      ],
      "metadata": {
        "id": "EJKiiEn4STwP"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Function to count files in each folder\n",
        "def count_files_in_folders(root_dir):\n",
        "    folder_counts = {}\n",
        "    for folder in os.listdir(root_dir):\n",
        "        folder_path = os.path.join(root_dir, folder)\n",
        "        if os.path.isdir(folder_path):\n",
        "            folder_counts[folder] = len(os.listdir(folder_path))\n",
        "    return folder_counts\n",
        "\n",
        "# Function to normalize images\n",
        "def normalize_images(image_paths):\n",
        "    images = []\n",
        "    for img_path in image_paths:\n",
        "        img = tf.keras.preprocessing.image.load_img(img_path, target_size=(224, 224))\n",
        "        img_array = tf.keras.preprocessing.image.img_to_array(img)\n",
        "        normalized_img = tf.keras.applications.mobilenet_v2.preprocess_input(img_array)\n",
        "        images.append(normalized_img)\n",
        "    return images\n",
        "\n",
        "# Function to unzip a folder\n",
        "def unzip_folder(zip_file, extract_to):\n",
        "    with zipfile.ZipFile(zip_file, 'r') as zip_ref:\n",
        "        zip_ref.extractall(extract_to)\n",
        "\n",
        "# Path to your zipped folder\n",
        "zip_file = \"/content/gwbz3fsgp8-1.zip\"\n",
        "\n",
        "# Directory to extract the contents of the zip file\n",
        "extract_to = \"path/to/extracted/folder\"\n",
        "\n",
        "# Create the directory if it doesn't exist\n",
        "if not os.path.exists(extract_to):\n",
        "    os.makedirs(extract_to)\n",
        "\n",
        "# Unzip the folder\n",
        "unzip_folder(zip_file, extract_to)\n",
        "\n",
        "# Path to the content folder containing all five image folders\n",
        "content_folder = extract_to\n",
        "\n",
        "# Count images in each folder\n",
        "folder_counts = count_files_in_folders(content_folder)\n",
        "\n",
        "# Create figure\n",
        "fig = go.Figure()\n",
        "\n",
        "# Define colors for bars\n",
        "colors = ['lightskyblue', 'lightgreen', 'salmon', 'lightyellow', 'lightpink']\n",
        "\n",
        "for i, folder in enumerate(folder_counts.keys()):\n",
        "    fig.add_trace(go.Bar(\n",
        "        x=[folder],\n",
        "        y=[folder_counts[folder]],\n",
        "        text=f\"{folder}: {folder_counts[folder]} images\",\n",
        "        hoverinfo=\"text\",\n",
        "        textposition='auto',\n",
        "        marker_color=colors[i % len(colors)]  # Use modulo operator to cycle through colors\n",
        "    ))\n",
        "\n",
        "# Update layout\n",
        "fig.update_layout(\n",
        "    title='Distribution of Images in Folders',\n",
        "    title_x=0.5,\n",
        "    xaxis=dict(title='Data Folders', title_standoff=25, showticklabels=False),\n",
        "    yaxis=dict(title='Number of Images'),\n",
        "    showlegend=False\n",
        ")\n",
        "\n",
        "# Show plot\n",
        "fig.show()\n",
        "\n",
        "# Normalize images\n",
        "normalized_images = {}\n",
        "for folder in folder_counts.keys():\n",
        "    folder_path = os.path.join(content_folder, folder)\n",
        "    image_paths = [os.path.join(folder_path, img) for img in os.listdir(folder_path)]\n",
        "    normalized_images[folder] = normalize_images(image_paths)\n",
        "\n",
        "# Now normalized_images contains normalized images for each folder"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 542
        },
        "id": "TEFozA5PIDIJ",
        "outputId": "b247ab1b-5d19-473c-ffaf-adb0a35b2417"
      },
      "execution_count": 4,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<html>\n",
              "<head><meta charset=\"utf-8\" /></head>\n",
              "<body>\n",
              "    <div>            <script src=\"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_SVG\"></script><script type=\"text/javascript\">if (window.MathJax && window.MathJax.Hub && window.MathJax.Hub.Config) {window.MathJax.Hub.Config({SVG: {font: \"STIX-Web\"}});}</script>                <script type=\"text/javascript\">window.PlotlyConfig = {MathJaxConfig: 'local'};</script>\n",
              "        <script charset=\"utf-8\" src=\"https://cdn.plot.ly/plotly-2.24.1.min.js\"></script>                <div id=\"4322a731-a225-41ee-a1af-1a901903fe0e\" class=\"plotly-graph-div\" style=\"height:525px; width:100%;\"></div>            <script type=\"text/javascript\">                                    window.PLOTLYENV=window.PLOTLYENV || {};                                    if (document.getElementById(\"4322a731-a225-41ee-a1af-1a901903fe0e\")) {                    Plotly.newPlot(                        \"4322a731-a225-41ee-a1af-1a901903fe0e\",                        [{\"hoverinfo\":\"text\",\"marker\":{\"color\":\"lightskyblue\"},\"text\":\"ECG Images of Myocardial Infarction Patients (77): 74 images\",\"textposition\":\"auto\",\"x\":[\"ECG Images of Myocardial Infarction Patients (77)\"],\"y\":[74],\"type\":\"bar\"},{\"hoverinfo\":\"text\",\"marker\":{\"color\":\"lightgreen\"},\"text\":\"ECG Images of COVID-19 Patients (250): 250 images\",\"textposition\":\"auto\",\"x\":[\"ECG Images of COVID-19 Patients (250)\"],\"y\":[250],\"type\":\"bar\"},{\"hoverinfo\":\"text\",\"marker\":{\"color\":\"salmon\"},\"text\":\"ECG Images of Patient that have abnormal heart beats (548): 546 images\",\"textposition\":\"auto\",\"x\":[\"ECG Images of Patient that have abnormal heart beats (548)\"],\"y\":[546],\"type\":\"bar\"},{\"hoverinfo\":\"text\",\"marker\":{\"color\":\"lightyellow\"},\"text\":\"ECG Images of Patient that have History of MI (203): 203 images\",\"textposition\":\"auto\",\"x\":[\"ECG Images of Patient that have History of MI (203)\"],\"y\":[203],\"type\":\"bar\"},{\"hoverinfo\":\"text\",\"marker\":{\"color\":\"lightpink\"},\"text\":\"Normal Person ECG Images (859): 859 images\",\"textposition\":\"auto\",\"x\":[\"Normal Person ECG Images (859)\"],\"y\":[859],\"type\":\"bar\"}],                        {\"template\":{\"data\":{\"histogram2dcontour\":[{\"type\":\"histogram2dcontour\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"choropleth\":[{\"type\":\"choropleth\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}],\"histogram2d\":[{\"type\":\"histogram2d\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"heatmap\":[{\"type\":\"heatmap\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"heatmapgl\":[{\"type\":\"heatmapgl\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"contourcarpet\":[{\"type\":\"contourcarpet\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}],\"contour\":[{\"type\":\"contour\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"surface\":[{\"type\":\"surface\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"mesh3d\":[{\"type\":\"mesh3d\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}],\"scatter\":[{\"fillpattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2},\"type\":\"scatter\"}],\"parcoords\":[{\"type\":\"parcoords\",\"line\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatterpolargl\":[{\"type\":\"scatterpolargl\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"bar\":[{\"error_x\":{\"color\":\"#2a3f5f\"},\"error_y\":{\"color\":\"#2a3f5f\"},\"marker\":{\"line\":{\"color\":\"#E5ECF6\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"bar\"}],\"scattergeo\":[{\"type\":\"scattergeo\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatterpolar\":[{\"type\":\"scatterpolar\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"histogram\":[{\"marker\":{\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"histogram\"}],\"scattergl\":[{\"type\":\"scattergl\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatter3d\":[{\"type\":\"scatter3d\",\"line\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scattermapbox\":[{\"type\":\"scattermapbox\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatterternary\":[{\"type\":\"scatterternary\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scattercarpet\":[{\"type\":\"scattercarpet\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"carpet\":[{\"aaxis\":{\"endlinecolor\":\"#2a3f5f\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"minorgridcolor\":\"white\",\"startlinecolor\":\"#2a3f5f\"},\"baxis\":{\"endlinecolor\":\"#2a3f5f\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"minorgridcolor\":\"white\",\"startlinecolor\":\"#2a3f5f\"},\"type\":\"carpet\"}],\"table\":[{\"cells\":{\"fill\":{\"color\":\"#EBF0F8\"},\"line\":{\"color\":\"white\"}},\"header\":{\"fill\":{\"color\":\"#C8D4E3\"},\"line\":{\"color\":\"white\"}},\"type\":\"table\"}],\"barpolar\":[{\"marker\":{\"line\":{\"color\":\"#E5ECF6\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"barpolar\"}],\"pie\":[{\"automargin\":true,\"type\":\"pie\"}]},\"layout\":{\"autotypenumbers\":\"strict\",\"colorway\":[\"#636efa\",\"#EF553B\",\"#00cc96\",\"#ab63fa\",\"#FFA15A\",\"#19d3f3\",\"#FF6692\",\"#B6E880\",\"#FF97FF\",\"#FECB52\"],\"font\":{\"color\":\"#2a3f5f\"},\"hovermode\":\"closest\",\"hoverlabel\":{\"align\":\"left\"},\"paper_bgcolor\":\"white\",\"plot_bgcolor\":\"#E5ECF6\",\"polar\":{\"bgcolor\":\"#E5ECF6\",\"angularaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"},\"radialaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"}},\"ternary\":{\"bgcolor\":\"#E5ECF6\",\"aaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"},\"baxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"},\"caxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"}},\"coloraxis\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"colorscale\":{\"sequential\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"sequentialminus\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"diverging\":[[0,\"#8e0152\"],[0.1,\"#c51b7d\"],[0.2,\"#de77ae\"],[0.3,\"#f1b6da\"],[0.4,\"#fde0ef\"],[0.5,\"#f7f7f7\"],[0.6,\"#e6f5d0\"],[0.7,\"#b8e186\"],[0.8,\"#7fbc41\"],[0.9,\"#4d9221\"],[1,\"#276419\"]]},\"xaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\",\"title\":{\"standoff\":15},\"zerolinecolor\":\"white\",\"automargin\":true,\"zerolinewidth\":2},\"yaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\",\"title\":{\"standoff\":15},\"zerolinecolor\":\"white\",\"automargin\":true,\"zerolinewidth\":2},\"scene\":{\"xaxis\":{\"backgroundcolor\":\"#E5ECF6\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"white\",\"gridwidth\":2},\"yaxis\":{\"backgroundcolor\":\"#E5ECF6\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"white\",\"gridwidth\":2},\"zaxis\":{\"backgroundcolor\":\"#E5ECF6\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"white\",\"gridwidth\":2}},\"shapedefaults\":{\"line\":{\"color\":\"#2a3f5f\"}},\"annotationdefaults\":{\"arrowcolor\":\"#2a3f5f\",\"arrowhead\":0,\"arrowwidth\":1},\"geo\":{\"bgcolor\":\"white\",\"landcolor\":\"#E5ECF6\",\"subunitcolor\":\"white\",\"showland\":true,\"showlakes\":true,\"lakecolor\":\"white\"},\"title\":{\"x\":0.05},\"mapbox\":{\"style\":\"light\"}}},\"title\":{\"text\":\"Distribution of Images in Folders\",\"x\":0.5},\"xaxis\":{\"title\":{\"text\":\"Data Folders\",\"standoff\":25},\"showticklabels\":false},\"yaxis\":{\"title\":{\"text\":\"Number of Images\"}},\"showlegend\":false},                        {\"responsive\": true}                    ).then(function(){\n",
              "                            \n",
              "var gd = document.getElementById('4322a731-a225-41ee-a1af-1a901903fe0e');\n",
              "var x = new MutationObserver(function (mutations, observer) {{\n",
              "        var display = window.getComputedStyle(gd).display;\n",
              "        if (!display || display === 'none') {{\n",
              "            console.log([gd, 'removed!']);\n",
              "            Plotly.purge(gd);\n",
              "            observer.disconnect();\n",
              "        }}\n",
              "}});\n",
              "\n",
              "// Listen for the removal of the full notebook cells\n",
              "var notebookContainer = gd.closest('#notebook-container');\n",
              "if (notebookContainer) {{\n",
              "    x.observe(notebookContainer, {childList: true});\n",
              "}}\n",
              "\n",
              "// Listen for the clearing of the current output cell\n",
              "var outputEl = gd.closest('.output');\n",
              "if (outputEl) {{\n",
              "    x.observe(outputEl, {childList: true});\n",
              "}}\n",
              "\n",
              "                        })                };                            </script>        </div>\n",
              "</body>\n",
              "</html>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# Sort folder_counts by counts\n",
        "sorted_folder_counts = dict(sorted(folder_counts.items(), key=operator.itemgetter(1), reverse=True))\n",
        "\n",
        "# Extract top two folders\n",
        "top_folders = list(sorted_folder_counts.keys())[:2]\n",
        "\n",
        "# Define colors for bars\n",
        "top_color = '#bd3c3c'\n",
        "other_color = 'lightgrey'\n",
        "\n",
        "# Create figure\n",
        "fig = go.Figure()\n",
        "\n",
        "for i, folder in enumerate(sorted_folder_counts.keys()):\n",
        "    bar_color = top_color if folder in top_folders else other_color\n",
        "    border_color = 'red' if folder in top_folders else None\n",
        "    fig.add_trace(go.Bar(\n",
        "        x=[folder],\n",
        "        y=[sorted_folder_counts[folder]],\n",
        "        text=f\"{folder}: {sorted_folder_counts[folder]} images\",\n",
        "        hoverinfo=\"text\",\n",
        "        textposition='auto',\n",
        "        marker_color=bar_color,\n",
        "        marker_line_color=border_color,\n",
        "        marker_line_width=1.5\n",
        "    ))\n",
        "\n",
        "# Update layout\n",
        "fig.update_layout(\n",
        "    title='Distribution of Images in Folders',\n",
        "    title_x=0.5,\n",
        "    xaxis=dict(title='Data Folders', title_standoff=25, showticklabels=False),\n",
        "    yaxis=dict(title='Number of Images'),\n",
        "    showlegend=False,\n",
        "    plot_bgcolor='#13141a',\n",
        "    paper_bgcolor='#13141a',\n",
        "    font=dict(color='lightgray')\n",
        ")\n",
        "\n",
        "# Show plot\n",
        "fig.show()\n"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 542
        },
        "id": "CXF6R7VV8MN6",
        "outputId": "f661765d-58a4-4819-d507-51be0a338fef"
      },
      "execution_count": 5,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<html>\n",
              "<head><meta charset=\"utf-8\" /></head>\n",
              "<body>\n",
              "    <div>            <script src=\"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_SVG\"></script><script type=\"text/javascript\">if (window.MathJax && window.MathJax.Hub && window.MathJax.Hub.Config) {window.MathJax.Hub.Config({SVG: {font: \"STIX-Web\"}});}</script>                <script type=\"text/javascript\">window.PlotlyConfig = {MathJaxConfig: 'local'};</script>\n",
              "        <script charset=\"utf-8\" src=\"https://cdn.plot.ly/plotly-2.24.1.min.js\"></script>                <div id=\"612ad8e6-90ed-42ac-85b3-808b062e64d1\" class=\"plotly-graph-div\" style=\"height:525px; width:100%;\"></div>            <script type=\"text/javascript\">                                    window.PLOTLYENV=window.PLOTLYENV || {};                                    if (document.getElementById(\"612ad8e6-90ed-42ac-85b3-808b062e64d1\")) {                    Plotly.newPlot(                        \"612ad8e6-90ed-42ac-85b3-808b062e64d1\",                        [{\"hoverinfo\":\"text\",\"marker\":{\"color\":\"#bd3c3c\",\"line\":{\"color\":\"red\",\"width\":1.5}},\"text\":\"Normal Person ECG Images (859): 859 images\",\"textposition\":\"auto\",\"x\":[\"Normal Person ECG Images (859)\"],\"y\":[859],\"type\":\"bar\"},{\"hoverinfo\":\"text\",\"marker\":{\"color\":\"#bd3c3c\",\"line\":{\"color\":\"red\",\"width\":1.5}},\"text\":\"ECG Images of Patient that have abnormal heart beats (548): 546 images\",\"textposition\":\"auto\",\"x\":[\"ECG Images of Patient that have abnormal heart beats (548)\"],\"y\":[546],\"type\":\"bar\"},{\"hoverinfo\":\"text\",\"marker\":{\"color\":\"lightgrey\",\"line\":{\"width\":1.5}},\"text\":\"ECG Images of COVID-19 Patients (250): 250 images\",\"textposition\":\"auto\",\"x\":[\"ECG Images of COVID-19 Patients (250)\"],\"y\":[250],\"type\":\"bar\"},{\"hoverinfo\":\"text\",\"marker\":{\"color\":\"lightgrey\",\"line\":{\"width\":1.5}},\"text\":\"ECG Images of Patient that have History of MI (203): 203 images\",\"textposition\":\"auto\",\"x\":[\"ECG Images of Patient that have History of MI (203)\"],\"y\":[203],\"type\":\"bar\"},{\"hoverinfo\":\"text\",\"marker\":{\"color\":\"lightgrey\",\"line\":{\"width\":1.5}},\"text\":\"ECG Images of Myocardial Infarction Patients (77): 74 images\",\"textposition\":\"auto\",\"x\":[\"ECG Images of Myocardial Infarction Patients (77)\"],\"y\":[74],\"type\":\"bar\"}],                        {\"template\":{\"data\":{\"histogram2dcontour\":[{\"type\":\"histogram2dcontour\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"choropleth\":[{\"type\":\"choropleth\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}],\"histogram2d\":[{\"type\":\"histogram2d\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"heatmap\":[{\"type\":\"heatmap\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"heatmapgl\":[{\"type\":\"heatmapgl\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"contourcarpet\":[{\"type\":\"contourcarpet\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}],\"contour\":[{\"type\":\"contour\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"surface\":[{\"type\":\"surface\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"mesh3d\":[{\"type\":\"mesh3d\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}],\"scatter\":[{\"fillpattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2},\"type\":\"scatter\"}],\"parcoords\":[{\"type\":\"parcoords\",\"line\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatterpolargl\":[{\"type\":\"scatterpolargl\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"bar\":[{\"error_x\":{\"color\":\"#2a3f5f\"},\"error_y\":{\"color\":\"#2a3f5f\"},\"marker\":{\"line\":{\"color\":\"#E5ECF6\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"bar\"}],\"scattergeo\":[{\"type\":\"scattergeo\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatterpolar\":[{\"type\":\"scatterpolar\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"histogram\":[{\"marker\":{\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"histogram\"}],\"scattergl\":[{\"type\":\"scattergl\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatter3d\":[{\"type\":\"scatter3d\",\"line\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scattermapbox\":[{\"type\":\"scattermapbox\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatterternary\":[{\"type\":\"scatterternary\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scattercarpet\":[{\"type\":\"scattercarpet\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"carpet\":[{\"aaxis\":{\"endlinecolor\":\"#2a3f5f\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"minorgridcolor\":\"white\",\"startlinecolor\":\"#2a3f5f\"},\"baxis\":{\"endlinecolor\":\"#2a3f5f\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"minorgridcolor\":\"white\",\"startlinecolor\":\"#2a3f5f\"},\"type\":\"carpet\"}],\"table\":[{\"cells\":{\"fill\":{\"color\":\"#EBF0F8\"},\"line\":{\"color\":\"white\"}},\"header\":{\"fill\":{\"color\":\"#C8D4E3\"},\"line\":{\"color\":\"white\"}},\"type\":\"table\"}],\"barpolar\":[{\"marker\":{\"line\":{\"color\":\"#E5ECF6\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"barpolar\"}],\"pie\":[{\"automargin\":true,\"type\":\"pie\"}]},\"layout\":{\"autotypenumbers\":\"strict\",\"colorway\":[\"#636efa\",\"#EF553B\",\"#00cc96\",\"#ab63fa\",\"#FFA15A\",\"#19d3f3\",\"#FF6692\",\"#B6E880\",\"#FF97FF\",\"#FECB52\"],\"font\":{\"color\":\"#2a3f5f\"},\"hovermode\":\"closest\",\"hoverlabel\":{\"align\":\"left\"},\"paper_bgcolor\":\"white\",\"plot_bgcolor\":\"#E5ECF6\",\"polar\":{\"bgcolor\":\"#E5ECF6\",\"angularaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"},\"radialaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"}},\"ternary\":{\"bgcolor\":\"#E5ECF6\",\"aaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"},\"baxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"},\"caxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"}},\"coloraxis\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"colorscale\":{\"sequential\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"sequentialminus\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"diverging\":[[0,\"#8e0152\"],[0.1,\"#c51b7d\"],[0.2,\"#de77ae\"],[0.3,\"#f1b6da\"],[0.4,\"#fde0ef\"],[0.5,\"#f7f7f7\"],[0.6,\"#e6f5d0\"],[0.7,\"#b8e186\"],[0.8,\"#7fbc41\"],[0.9,\"#4d9221\"],[1,\"#276419\"]]},\"xaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\",\"title\":{\"standoff\":15},\"zerolinecolor\":\"white\",\"automargin\":true,\"zerolinewidth\":2},\"yaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\",\"title\":{\"standoff\":15},\"zerolinecolor\":\"white\",\"automargin\":true,\"zerolinewidth\":2},\"scene\":{\"xaxis\":{\"backgroundcolor\":\"#E5ECF6\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"white\",\"gridwidth\":2},\"yaxis\":{\"backgroundcolor\":\"#E5ECF6\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"white\",\"gridwidth\":2},\"zaxis\":{\"backgroundcolor\":\"#E5ECF6\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"white\",\"gridwidth\":2}},\"shapedefaults\":{\"line\":{\"color\":\"#2a3f5f\"}},\"annotationdefaults\":{\"arrowcolor\":\"#2a3f5f\",\"arrowhead\":0,\"arrowwidth\":1},\"geo\":{\"bgcolor\":\"white\",\"landcolor\":\"#E5ECF6\",\"subunitcolor\":\"white\",\"showland\":true,\"showlakes\":true,\"lakecolor\":\"white\"},\"title\":{\"x\":0.05},\"mapbox\":{\"style\":\"light\"}}},\"title\":{\"text\":\"Distribution of Images in Folders\",\"x\":0.5},\"xaxis\":{\"title\":{\"text\":\"Data Folders\",\"standoff\":25},\"showticklabels\":false},\"font\":{\"color\":\"lightgray\"},\"yaxis\":{\"title\":{\"text\":\"Number of Images\"}},\"showlegend\":false,\"plot_bgcolor\":\"#13141a\",\"paper_bgcolor\":\"#13141a\"},                        {\"responsive\": true}                    ).then(function(){\n",
              "                            \n",
              "var gd = document.getElementById('612ad8e6-90ed-42ac-85b3-808b062e64d1');\n",
              "var x = new MutationObserver(function (mutations, observer) {{\n",
              "        var display = window.getComputedStyle(gd).display;\n",
              "        if (!display || display === 'none') {{\n",
              "            console.log([gd, 'removed!']);\n",
              "            Plotly.purge(gd);\n",
              "            observer.disconnect();\n",
              "        }}\n",
              "}});\n",
              "\n",
              "// Listen for the removal of the full notebook cells\n",
              "var notebookContainer = gd.closest('#notebook-container');\n",
              "if (notebookContainer) {{\n",
              "    x.observe(notebookContainer, {childList: true});\n",
              "}}\n",
              "\n",
              "// Listen for the clearing of the current output cell\n",
              "var outputEl = gd.closest('.output');\n",
              "if (outputEl) {{\n",
              "    x.observe(outputEl, {childList: true});\n",
              "}}\n",
              "\n",
              "                        })                };                            </script>        </div>\n",
              "</body>\n",
              "</html>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "# Filtering the Dataset - Normal and Abnormal Hear Beat (540 images each)"
      ],
      "metadata": {
        "id": "OTkj_-GrYM1d"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Function to randomly select images from a folder\n",
        "def random_select_images(folder_path, num_images):\n",
        "    image_files = os.listdir(folder_path)\n",
        "    selected_images = random.sample(image_files, num_images)\n",
        "    return selected_images\n",
        "\n",
        "# Define paths to the \"ECG - Normal\" and \"ECG - Abnormal\" folders\n",
        "normal_folder = \"/content/path/to/extracted/folder/Normal Person ECG Images (859)\"\n",
        "abnormal_folder = \"/content/path/to/extracted/folder/ECG Images of Patient that have abnormal heart beats (548)\"\n",
        "\n",
        "# Define paths for the new folders that will contain selected images\n",
        "selected_normal_folder = \"/content/selected_normal\"\n",
        "selected_abnormal_folder = \"/content/selected_abnormal\"\n",
        "\n",
        "# Create directories for the selected folders\n",
        "os.makedirs(selected_normal_folder, exist_ok=True)\n",
        "os.makedirs(selected_abnormal_folder, exist_ok=True)\n",
        "\n",
        "# Randomly select and move 540 images from each folder to the new folders\n",
        "num_images_per_set = 540\n",
        "selected_normal_images = random_select_images(normal_folder, num_images_per_set)\n",
        "selected_abnormal_images = random_select_images(abnormal_folder, num_images_per_set)\n",
        "\n",
        "for image in selected_normal_images:\n",
        "    src_path = os.path.join(normal_folder, image)\n",
        "    dest_path = os.path.join(selected_normal_folder, image)\n",
        "    shutil.copy(src_path, dest_path)\n",
        "\n",
        "for image in selected_abnormal_images:\n",
        "    src_path = os.path.join(abnormal_folder, image)\n",
        "    dest_path = os.path.join(selected_abnormal_folder, image)\n",
        "    shutil.copy(src_path, dest_path)\n",
        "\n",
        "# Print the counts\n",
        "print(\"Number of images selected for normal folder:\", len(selected_normal_images))\n",
        "print(\"Number of images selected for abnormal folder:\", len(selected_abnormal_images))\n"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "GX0JpwXxaHfx",
        "outputId": "6f3c2095-5cd3-4ac1-8ff3-04a647d54bcb"
      },
      "execution_count": 7,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Number of images selected for normal folder: 540\n",
            "Number of images selected for abnormal folder: 540\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "# Splitting the Dataset into Training, Testing and Validation (80-10-10)"
      ],
      "metadata": {
        "id": "DVDNDgmtdK_Y"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Function to randomly select images from a folder\n",
        "def random_select_images(folder_path, num_images):\n",
        "    image_files = os.listdir(folder_path)\n",
        "    selected_images = random.sample(image_files, num_images)\n",
        "    return selected_images\n",
        "\n",
        "# Define paths for the new folders that will contain selected images\n",
        "selected_normal_folder = \"/content/selected_normal\"\n",
        "selected_abnormal_folder = \"/content/selected_abnormal\"\n",
        "\n",
        "# Define paths for the new folders that will contain training, testing, and validation sets\n",
        "train_normal_folder = \"/content/train/normal\"\n",
        "train_abnormal_folder = \"/content/train/abnormal\"\n",
        "test_normal_folder = \"/content/test/normal\"\n",
        "test_abnormal_folder = \"/content/test/abnormal\"\n",
        "val_normal_folder = \"/content/val/normal\"\n",
        "val_abnormal_folder = \"/content/val/abnormal\"\n",
        "\n",
        "# Create directories for the new folders\n",
        "for folder in [train_normal_folder, train_abnormal_folder, test_normal_folder, test_abnormal_folder, val_normal_folder, val_abnormal_folder]:\n",
        "    os.makedirs(folder, exist_ok=True)\n",
        "\n",
        "# Split selected images into training, testing, and validation sets\n",
        "normal_images = os.listdir(selected_normal_folder)\n",
        "abnormal_images = os.listdir(selected_abnormal_folder)\n",
        "\n",
        "# Splitting the normal images\n",
        "train_normal, testval_normal = train_test_split(normal_images, test_size=0.3, random_state=42)\n",
        "test_normal, val_normal = train_test_split(testval_normal, test_size=0.5, random_state=42)\n",
        "\n",
        "# Splitting the abnormal images\n",
        "train_abnormal, testval_abnormal = train_test_split(abnormal_images, test_size=0.3, random_state=42)\n",
        "test_abnormal, val_abnormal = train_test_split(testval_abnormal, test_size=0.5, random_state=42)\n",
        "\n",
        "# Move images to respective folders\n",
        "for image in train_normal:\n",
        "    src_path = os.path.join(selected_normal_folder, image)\n",
        "    dest_path = os.path.join(train_normal_folder, image)\n",
        "    shutil.copy(src_path, dest_path)\n",
        "\n",
        "for image in test_normal:\n",
        "    src_path = os.path.join(selected_normal_folder, image)\n",
        "    dest_path = os.path.join(test_normal_folder, image)\n",
        "    shutil.copy(src_path, dest_path)\n",
        "\n",
        "for image in val_normal:\n",
        "    src_path = os.path.join(selected_normal_folder, image)\n",
        "    dest_path = os.path.join(val_normal_folder, image)\n",
        "    shutil.copy(src_path, dest_path)\n",
        "\n",
        "for image in train_abnormal:\n",
        "    src_path = os.path.join(selected_abnormal_folder, image)\n",
        "    dest_path = os.path.join(train_abnormal_folder, image)\n",
        "    shutil.copy(src_path, dest_path)\n",
        "\n",
        "for image in test_abnormal:\n",
        "    src_path = os.path.join(selected_abnormal_folder, image)\n",
        "    dest_path = os.path.join(test_abnormal_folder, image)\n",
        "    shutil.copy(src_path, dest_path)\n",
        "\n",
        "for image in val_abnormal:\n",
        "    src_path = os.path.join(selected_abnormal_folder, image)\n",
        "    dest_path = os.path.join(val_abnormal_folder, image)\n",
        "    shutil.copy(src_path, dest_path)\n",
        "\n",
        "# Print counts\n",
        "print(\"Training set size (normal):\", len(train_normal))\n",
        "print(\"Testing set size (normal):\", len(test_normal))\n",
        "print(\"Validation set size (normal):\", len(val_normal))\n",
        "print(\"Training set size (abnormal):\", len(train_abnormal))\n",
        "print(\"Testing set size (abnormal):\", len(test_abnormal))\n",
        "print(\"Validation set size (abnormal):\", len(val_abnormal))"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "AMvcDTq_bz-f",
        "outputId": "16322a02-ee53-4896-c5f7-3ce11eda0e6f"
      },
      "execution_count": 8,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Training set size (normal): 378\n",
            "Testing set size (normal): 81\n",
            "Validation set size (normal): 81\n",
            "Training set size (abnormal): 378\n",
            "Testing set size (abnormal): 81\n",
            "Validation set size (abnormal): 81\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "# Create a CNN Model"
      ],
      "metadata": {
        "id": "9dKFxuO4dULz"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Set random seed for reproducibility\n",
        "np.random.seed(42)\n",
        "tf.random.set_seed(42)\n",
        "\n",
        "# Define data directories\n",
        "train_dir = \"/content/train\"\n",
        "val_dir = \"/content/val\"\n",
        "test_dir = \"/content/test\"\n",
        "\n",
        "# Define image dimensions\n",
        "img_width, img_height = 224, 224\n",
        "\n",
        "# Define batch size\n",
        "batch_size = 32\n",
        "\n",
        "# Data preprocessing and augmentation\n",
        "train_datagen = ImageDataGenerator(rescale=1./255,\n",
        "                                   rotation_range=15,\n",
        "                                   width_shift_range=0.1,\n",
        "                                   height_shift_range=0.1,\n",
        "                                   shear_range=0.1,\n",
        "                                   zoom_range=0.1,\n",
        "                                   horizontal_flip=True,\n",
        "                                   fill_mode='nearest')\n",
        "\n",
        "val_datagen = ImageDataGenerator(rescale=1./255)\n",
        "\n",
        "# Prepare data generators\n",
        "train_generator = train_datagen.flow_from_directory(train_dir,\n",
        "                                                    target_size=(img_width, img_height),\n",
        "                                                    batch_size=batch_size,\n",
        "                                                    class_mode='binary')\n",
        "\n",
        "val_generator = val_datagen.flow_from_directory(val_dir,\n",
        "                                                target_size=(img_width, img_height),\n",
        "                                                batch_size=batch_size,\n",
        "                                                class_mode='binary')\n",
        "\n",
        "test_generator = val_datagen.flow_from_directory(test_dir,\n",
        "                                                 target_size=(img_width, img_height),\n",
        "                                                 batch_size=batch_size,\n",
        "                                                 class_mode='binary',\n",
        "                                                 shuffle=False)\n",
        "\n",
        "# Define the CNN model\n",
        "model = Sequential([\n",
        "    Conv2D(32, (3, 3), activation='relu', input_shape=(img_width, img_height, 3)),\n",
        "    MaxPooling2D((2, 2)),\n",
        "    Conv2D(64, (3, 3), activation='relu'),\n",
        "    MaxPooling2D((2, 2)),\n",
        "    Conv2D(128, (3, 3), activation='relu'),\n",
        "    MaxPooling2D((2, 2)),\n",
        "    Conv2D(128, (3, 3), activation='relu'),\n",
        "    MaxPooling2D((2, 2)),\n",
        "    Flatten(),\n",
        "    Dense(512, activation='relu'),\n",
        "    Dropout(0.5),\n",
        "    Dense(1, activation='sigmoid')\n",
        "])\n",
        "\n",
        "# Compile the model\n",
        "model.compile(optimizer='adam',\n",
        "              loss='binary_crossentropy',\n",
        "              metrics=['accuracy'])\n",
        "\n",
        "# Train the model\n",
        "history = model.fit(train_generator,\n",
        "                    steps_per_epoch=train_generator.samples // batch_size,\n",
        "                    epochs=20,\n",
        "                    validation_data=val_generator,\n",
        "                    validation_steps=val_generator.samples // batch_size)\n",
        "\n",
        "# Evaluate the model on the test data\n",
        "test_loss, test_accuracy = model.evaluate(test_generator, steps=test_generator.samples // batch_size)\n",
        "print(\"Test Accuracy:\", test_accuracy)\n"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 1000
        },
        "id": "XKNpHwYMdX7V",
        "outputId": "00398498-24a5-4a98-e383-3f83e01510c8"
      },
      "execution_count": 10,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Found 756 images belonging to 2 classes.\n",
            "Found 162 images belonging to 2 classes.\n",
            "Found 162 images belonging to 2 classes.\n",
            "Epoch 1/100\n",
            "23/23 [==============================] - 30s 1s/step - loss: 0.7381 - accuracy: 0.5097 - val_loss: 0.6889 - val_accuracy: 0.5000\n",
            "Epoch 2/100\n",
            "23/23 [==============================] - 27s 1s/step - loss: 0.6774 - accuracy: 0.5677 - val_loss: 0.6483 - val_accuracy: 0.4938\n",
            "Epoch 3/100\n",
            "23/23 [==============================] - 27s 1s/step - loss: 0.6466 - accuracy: 0.5994 - val_loss: 1.0068 - val_accuracy: 0.5188\n",
            "Epoch 4/100\n",
            "23/23 [==============================] - 27s 1s/step - loss: 0.5704 - accuracy: 0.6948 - val_loss: 0.8938 - val_accuracy: 0.5375\n",
            "Epoch 5/100\n",
            "23/23 [==============================] - 27s 1s/step - loss: 0.5064 - accuracy: 0.7500 - val_loss: 0.5786 - val_accuracy: 0.7563\n",
            "Epoch 6/100\n",
            "23/23 [==============================] - 27s 1s/step - loss: 0.4562 - accuracy: 0.7859 - val_loss: 1.0188 - val_accuracy: 0.5312\n",
            "Epoch 7/100\n",
            "23/23 [==============================] - 28s 1s/step - loss: 0.4090 - accuracy: 0.8122 - val_loss: 1.7050 - val_accuracy: 0.4938\n",
            "Epoch 8/100\n",
            "23/23 [==============================] - 25s 1s/step - loss: 0.4184 - accuracy: 0.8039 - val_loss: 0.3684 - val_accuracy: 0.8313\n",
            "Epoch 9/100\n",
            "23/23 [==============================] - 25s 1s/step - loss: 0.3871 - accuracy: 0.8191 - val_loss: 1.4707 - val_accuracy: 0.5063\n",
            "Epoch 10/100\n",
            "23/23 [==============================] - 25s 1s/step - loss: 0.3733 - accuracy: 0.8467 - val_loss: 0.7936 - val_accuracy: 0.6000\n",
            "Epoch 11/100\n",
            "23/23 [==============================] - 26s 1s/step - loss: 0.3337 - accuracy: 0.8564 - val_loss: 1.5813 - val_accuracy: 0.5063\n",
            "Epoch 12/100\n",
            "23/23 [==============================] - 25s 1s/step - loss: 0.3395 - accuracy: 0.8522 - val_loss: 1.1232 - val_accuracy: 0.5188\n",
            "Epoch 13/100\n",
            "23/23 [==============================] - 26s 1s/step - loss: 0.3334 - accuracy: 0.8383 - val_loss: 1.3449 - val_accuracy: 0.5375\n",
            "Epoch 14/100\n",
            "23/23 [==============================] - 26s 1s/step - loss: 0.3438 - accuracy: 0.8384 - val_loss: 0.7896 - val_accuracy: 0.6313\n",
            "Epoch 15/100\n",
            "23/23 [==============================] - 28s 1s/step - loss: 0.3432 - accuracy: 0.8301 - val_loss: 1.1792 - val_accuracy: 0.5500\n",
            "Epoch 16/100\n",
            "23/23 [==============================] - 25s 1s/step - loss: 0.3492 - accuracy: 0.8453 - val_loss: 0.6468 - val_accuracy: 0.6875\n",
            "Epoch 17/100\n",
            "23/23 [==============================] - 27s 1s/step - loss: 0.3353 - accuracy: 0.8412 - val_loss: 0.6379 - val_accuracy: 0.7188\n",
            "Epoch 18/100\n",
            "23/23 [==============================] - 27s 1s/step - loss: 0.3332 - accuracy: 0.8508 - val_loss: 0.8088 - val_accuracy: 0.6812\n",
            "Epoch 19/100\n",
            "23/23 [==============================] - 27s 1s/step - loss: 0.3311 - accuracy: 0.8522 - val_loss: 0.3109 - val_accuracy: 0.8562\n",
            "Epoch 20/100\n",
            "23/23 [==============================] - 26s 1s/step - loss: 0.3676 - accuracy: 0.8343 - val_loss: 0.4724 - val_accuracy: 0.8000\n",
            "Epoch 21/100\n",
            "23/23 [==============================] - 25s 1s/step - loss: 0.3427 - accuracy: 0.8494 - val_loss: 0.9662 - val_accuracy: 0.6250\n",
            "Epoch 22/100\n",
            "23/23 [==============================] - 27s 1s/step - loss: 0.3332 - accuracy: 0.8508 - val_loss: 0.9368 - val_accuracy: 0.6313\n",
            "Epoch 23/100\n",
            "23/23 [==============================] - 28s 1s/step - loss: 0.3282 - accuracy: 0.8715 - val_loss: 1.1186 - val_accuracy: 0.5500\n",
            "Epoch 24/100\n",
            "23/23 [==============================] - 25s 1s/step - loss: 0.3444 - accuracy: 0.8481 - val_loss: 1.0755 - val_accuracy: 0.5500\n",
            "Epoch 25/100\n",
            "23/23 [==============================] - 26s 1s/step - loss: 0.3234 - accuracy: 0.8591 - val_loss: 0.7011 - val_accuracy: 0.6500\n",
            "Epoch 26/100\n",
            "23/23 [==============================] - 26s 1s/step - loss: 0.3226 - accuracy: 0.8481 - val_loss: 1.3202 - val_accuracy: 0.5500\n",
            "Epoch 27/100\n",
            "23/23 [==============================] - 28s 1s/step - loss: 0.3196 - accuracy: 0.8619 - val_loss: 0.6187 - val_accuracy: 0.7563\n",
            "Epoch 28/100\n",
            "23/23 [==============================] - 26s 1s/step - loss: 0.3048 - accuracy: 0.8840 - val_loss: 1.2122 - val_accuracy: 0.5625\n",
            "Epoch 29/100\n",
            "23/23 [==============================] - 25s 1s/step - loss: 0.3340 - accuracy: 0.8536 - val_loss: 0.4454 - val_accuracy: 0.8375\n",
            "Epoch 30/100\n",
            "23/23 [==============================] - 27s 1s/step - loss: 0.3468 - accuracy: 0.8467 - val_loss: 0.2659 - val_accuracy: 0.8875\n",
            "Epoch 31/100\n",
            "23/23 [==============================] - 27s 1s/step - loss: 0.3324 - accuracy: 0.8425 - val_loss: 0.4369 - val_accuracy: 0.8250\n",
            "Epoch 32/100\n",
            "23/23 [==============================] - 27s 1s/step - loss: 0.3243 - accuracy: 0.8619 - val_loss: 0.7384 - val_accuracy: 0.6750\n",
            "Epoch 33/100\n",
            "23/23 [==============================] - 27s 1s/step - loss: 0.3170 - accuracy: 0.8591 - val_loss: 0.9337 - val_accuracy: 0.5875\n",
            "Epoch 34/100\n",
            "23/23 [==============================] - 26s 1s/step - loss: 0.3428 - accuracy: 0.8439 - val_loss: 0.6351 - val_accuracy: 0.7437\n",
            "Epoch 35/100\n",
            "23/23 [==============================] - 26s 1s/step - loss: 0.3541 - accuracy: 0.8467 - val_loss: 0.6283 - val_accuracy: 0.7312\n",
            "Epoch 36/100\n",
            " 6/23 [======>.......................] - ETA: 14s - loss: 0.3696 - accuracy: 0.8281"
          ]
        },
        {
          "output_type": "error",
          "ename": "KeyboardInterrupt",
          "evalue": "",
          "traceback": [
            "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
            "\u001b[0;31mKeyboardInterrupt\u001b[0m                         Traceback (most recent call last)",
            "\u001b[0;32m<ipython-input-10-56cf32e0ef8c>\u001b[0m in \u001b[0;36m<cell line: 67>\u001b[0;34m()\u001b[0m\n\u001b[1;32m     65\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     66\u001b[0m \u001b[0;31m# Train the model\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 67\u001b[0;31m history = model.fit(train_generator,\n\u001b[0m\u001b[1;32m     68\u001b[0m                     \u001b[0msteps_per_epoch\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mtrain_generator\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msamples\u001b[0m \u001b[0;34m//\u001b[0m \u001b[0mbatch_size\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     69\u001b[0m                     \u001b[0mepochs\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m100\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/keras/src/utils/traceback_utils.py\u001b[0m in \u001b[0;36merror_handler\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m     63\u001b[0m         \u001b[0mfiltered_tb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     64\u001b[0m         \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 65\u001b[0;31m             \u001b[0;32mreturn\u001b[0m \u001b[0mfn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     66\u001b[0m         \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     67\u001b[0m             \u001b[0mfiltered_tb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_process_traceback_frames\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0me\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__traceback__\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/keras/src/engine/training.py\u001b[0m in \u001b[0;36mfit\u001b[0;34m(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_batch_size, validation_freq, max_queue_size, workers, use_multiprocessing)\u001b[0m\n\u001b[1;32m   1805\u001b[0m                         ):\n\u001b[1;32m   1806\u001b[0m                             \u001b[0mcallbacks\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mon_train_batch_begin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mstep\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1807\u001b[0;31m                             \u001b[0mtmp_logs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtrain_function\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0miterator\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1808\u001b[0m                             \u001b[0;32mif\u001b[0m \u001b[0mdata_handler\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mshould_sync\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1809\u001b[0m                                 \u001b[0mcontext\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0masync_wait\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/tensorflow/python/util/traceback_utils.py\u001b[0m in \u001b[0;36merror_handler\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m    148\u001b[0m     \u001b[0mfiltered_tb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    149\u001b[0m     \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 150\u001b[0;31m       \u001b[0;32mreturn\u001b[0m \u001b[0mfn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    151\u001b[0m     \u001b[0;32mexcept\u001b[0m \u001b[0mException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    152\u001b[0m       \u001b[0mfiltered_tb\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_process_traceback_frames\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0me\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__traceback__\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/tensorflow/python/eager/polymorphic_function/polymorphic_function.py\u001b[0m in \u001b[0;36m__call__\u001b[0;34m(self, *args, **kwds)\u001b[0m\n\u001b[1;32m    830\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    831\u001b[0m       \u001b[0;32mwith\u001b[0m \u001b[0mOptionalXlaContext\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_jit_compile\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 832\u001b[0;31m         \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_call\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwds\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    833\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    834\u001b[0m       \u001b[0mnew_tracing_count\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexperimental_get_tracing_count\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/tensorflow/python/eager/polymorphic_function/polymorphic_function.py\u001b[0m in \u001b[0;36m_call\u001b[0;34m(self, *args, **kwds)\u001b[0m\n\u001b[1;32m    866\u001b[0m       \u001b[0;31m# In this case we have created variables on the first call, so we run the\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    867\u001b[0m       \u001b[0;31m# defunned version which is guaranteed to never create variables.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 868\u001b[0;31m       return tracing_compilation.call_function(\n\u001b[0m\u001b[1;32m    869\u001b[0m           \u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkwds\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_no_variable_creation_config\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    870\u001b[0m       )\n",
            "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/tensorflow/python/eager/polymorphic_function/tracing_compilation.py\u001b[0m in \u001b[0;36mcall_function\u001b[0;34m(args, kwargs, tracing_options)\u001b[0m\n\u001b[1;32m    137\u001b[0m   \u001b[0mbound_args\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfunction\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfunction_type\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mbind\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    138\u001b[0m   \u001b[0mflat_inputs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mfunction\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfunction_type\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0munpack_inputs\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mbound_args\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 139\u001b[0;31m   return function._call_flat(  # pylint: disable=protected-access\n\u001b[0m\u001b[1;32m    140\u001b[0m       \u001b[0mflat_inputs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcaptured_inputs\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mfunction\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcaptured_inputs\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    141\u001b[0m   )\n",
            "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/tensorflow/python/eager/polymorphic_function/concrete_function.py\u001b[0m in \u001b[0;36m_call_flat\u001b[0;34m(self, tensor_inputs, captured_inputs)\u001b[0m\n\u001b[1;32m   1321\u001b[0m         and executing_eagerly):\n\u001b[1;32m   1322\u001b[0m       \u001b[0;31m# No tape is watching; skip to running the function.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1323\u001b[0;31m       \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_inference_function\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcall_preflattened\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   1324\u001b[0m     forward_backward = self._select_forward_and_backward_functions(\n\u001b[1;32m   1325\u001b[0m         \u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/tensorflow/python/eager/polymorphic_function/atomic_function.py\u001b[0m in \u001b[0;36mcall_preflattened\u001b[0;34m(self, args)\u001b[0m\n\u001b[1;32m    214\u001b[0m   \u001b[0;32mdef\u001b[0m \u001b[0mcall_preflattened\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0margs\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mSequence\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mcore\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mTensor\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0mAny\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    215\u001b[0m     \u001b[0;34m\"\"\"Calls with flattened tensor inputs and returns the structured output.\"\"\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 216\u001b[0;31m     \u001b[0mflat_outputs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcall_flat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    217\u001b[0m     \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfunction_type\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpack_output\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mflat_outputs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    218\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/tensorflow/python/eager/polymorphic_function/atomic_function.py\u001b[0m in \u001b[0;36mcall_flat\u001b[0;34m(self, *args)\u001b[0m\n\u001b[1;32m    249\u001b[0m         \u001b[0;32mwith\u001b[0m \u001b[0mrecord\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstop_recording\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    250\u001b[0m           \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_bound_context\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexecuting_eagerly\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 251\u001b[0;31m             outputs = self._bound_context.call_function(\n\u001b[0m\u001b[1;32m    252\u001b[0m                 \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    253\u001b[0m                 \u001b[0mlist\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/tensorflow/python/eager/context.py\u001b[0m in \u001b[0;36mcall_function\u001b[0;34m(self, name, tensor_inputs, num_outputs)\u001b[0m\n\u001b[1;32m   1484\u001b[0m     \u001b[0mcancellation_context\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcancellation\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcontext\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1485\u001b[0m     \u001b[0;32mif\u001b[0m \u001b[0mcancellation_context\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1486\u001b[0;31m       outputs = execute.execute(\n\u001b[0m\u001b[1;32m   1487\u001b[0m           \u001b[0mname\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdecode\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"utf-8\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   1488\u001b[0m           \u001b[0mnum_outputs\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mnum_outputs\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;32m/usr/local/lib/python3.10/dist-packages/tensorflow/python/eager/execute.py\u001b[0m in \u001b[0;36mquick_execute\u001b[0;34m(op_name, num_outputs, inputs, attrs, ctx, name)\u001b[0m\n\u001b[1;32m     51\u001b[0m   \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     52\u001b[0m     \u001b[0mctx\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mensure_initialized\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 53\u001b[0;31m     tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,\n\u001b[0m\u001b[1;32m     54\u001b[0m                                         inputs, attrs, num_outputs)\n\u001b[1;32m     55\u001b[0m   \u001b[0;32mexcept\u001b[0m \u001b[0mcore\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_NotOkStatusException\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
            "\u001b[0;31mKeyboardInterrupt\u001b[0m: "
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "# ResNet50 Model"
      ],
      "metadata": {
        "id": "iGHI-Lpvi17n"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "# Load the pre-trained ResNet50 model without the top classification layer\n",
        "base_model = ResNet50(weights='imagenet', include_top=False, input_shape=(img_width, img_height, 3))\n",
        "\n",
        "# Freeze the base model layers\n",
        "for layer in base_model.layers:\n",
        "    layer.trainable = False\n",
        "\n",
        "# Add custom classification layers on top of ResNet50\n",
        "model = Sequential([\n",
        "    base_model,\n",
        "    GlobalAveragePooling2D(),\n",
        "    Dense(256, activation='relu'),\n",
        "    Dense(1, activation='sigmoid')\n",
        "])\n",
        "\n",
        "# Compile the model\n",
        "model.compile(optimizer='adam',\n",
        "              loss='binary_crossentropy',\n",
        "              metrics=['accuracy'])\n",
        "\n",
        "# Train the model\n",
        "history = model.fit(train_generator,\n",
        "                    steps_per_epoch=train_generator.samples // batch_size,\n",
        "                    epochs=20,\n",
        "                    validation_data=val_generator,\n",
        "                    validation_steps=val_generator.samples // batch_size)\n",
        "\n",
        "# Evaluate the model on the test data\n",
        "test_loss, test_accuracy = model.evaluate(test_generator, steps=test_generator.samples // batch_size)\n",
        "print(\"Test Accuracy:\", test_accuracy)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "h6VGPtPMi1i5",
        "outputId": "dbbff554-d30e-4f08-fac9-3ecc2fcf915e"
      },
      "execution_count": 11,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Downloading data from https://storage.googleapis.com/tensorflow/keras-applications/resnet/resnet50_weights_tf_dim_ordering_tf_kernels_notop.h5\n",
            "94765736/94765736 [==============================] - 0s 0us/step\n",
            "Epoch 1/20\n",
            "23/23 [==============================] - 33s 1s/step - loss: 0.7140 - accuracy: 0.5476 - val_loss: 0.6118 - val_accuracy: 0.5875\n",
            "Epoch 2/20\n",
            "23/23 [==============================] - 28s 1s/step - loss: 0.5828 - accuracy: 0.7072 - val_loss: 0.6098 - val_accuracy: 0.6000\n",
            "Epoch 3/20\n",
            "23/23 [==============================] - 26s 1s/step - loss: 0.5587 - accuracy: 0.6851 - val_loss: 0.6143 - val_accuracy: 0.6187\n",
            "Epoch 4/20\n",
            "23/23 [==============================] - 26s 1s/step - loss: 0.5377 - accuracy: 0.7238 - val_loss: 0.7082 - val_accuracy: 0.5375\n",
            "Epoch 5/20\n",
            "23/23 [==============================] - 27s 1s/step - loss: 0.5268 - accuracy: 0.7086 - val_loss: 0.5554 - val_accuracy: 0.7000\n",
            "Epoch 6/20\n",
            "23/23 [==============================] - 26s 1s/step - loss: 0.5165 - accuracy: 0.7293 - val_loss: 0.6009 - val_accuracy: 0.6625\n",
            "Epoch 7/20\n",
            "23/23 [==============================] - 26s 1s/step - loss: 0.5318 - accuracy: 0.7238 - val_loss: 0.5674 - val_accuracy: 0.6750\n",
            "Epoch 8/20\n",
            "23/23 [==============================] - 26s 1s/step - loss: 0.5121 - accuracy: 0.7293 - val_loss: 0.6392 - val_accuracy: 0.6375\n",
            "Epoch 9/20\n",
            "23/23 [==============================] - 26s 1s/step - loss: 0.5242 - accuracy: 0.7182 - val_loss: 0.5963 - val_accuracy: 0.6812\n",
            "Epoch 10/20\n",
            "23/23 [==============================] - 27s 1s/step - loss: 0.5740 - accuracy: 0.6796 - val_loss: 0.8757 - val_accuracy: 0.5125\n",
            "Epoch 11/20\n",
            "23/23 [==============================] - 27s 1s/step - loss: 0.5350 - accuracy: 0.7169 - val_loss: 0.8928 - val_accuracy: 0.5063\n",
            "Epoch 12/20\n",
            "23/23 [==============================] - 26s 1s/step - loss: 0.5104 - accuracy: 0.7279 - val_loss: 0.6556 - val_accuracy: 0.6313\n",
            "Epoch 13/20\n",
            "23/23 [==============================] - 26s 1s/step - loss: 0.5128 - accuracy: 0.7265 - val_loss: 0.6105 - val_accuracy: 0.6625\n",
            "Epoch 14/20\n",
            "23/23 [==============================] - 26s 1s/step - loss: 0.5060 - accuracy: 0.7459 - val_loss: 0.7972 - val_accuracy: 0.5375\n",
            "Epoch 15/20\n",
            "23/23 [==============================] - 26s 1s/step - loss: 0.4883 - accuracy: 0.7486 - val_loss: 0.7278 - val_accuracy: 0.6125\n",
            "Epoch 16/20\n",
            "23/23 [==============================] - 26s 1s/step - loss: 0.5338 - accuracy: 0.6961 - val_loss: 0.7335 - val_accuracy: 0.6125\n",
            "Epoch 17/20\n",
            "23/23 [==============================] - 28s 1s/step - loss: 0.5038 - accuracy: 0.7486 - val_loss: 0.7861 - val_accuracy: 0.5688\n",
            "Epoch 18/20\n",
            "23/23 [==============================] - 26s 1s/step - loss: 0.5169 - accuracy: 0.7431 - val_loss: 0.5684 - val_accuracy: 0.6687\n",
            "Epoch 19/20\n",
            "23/23 [==============================] - 26s 1s/step - loss: 0.5291 - accuracy: 0.7279 - val_loss: 0.6061 - val_accuracy: 0.6812\n",
            "Epoch 20/20\n",
            "23/23 [==============================] - 26s 1s/step - loss: 0.5145 - accuracy: 0.7155 - val_loss: 0.7319 - val_accuracy: 0.6000\n",
            "5/5 [==============================] - 4s 756ms/step - loss: 0.7281 - accuracy: 0.5500\n",
            "Test Accuracy: 0.550000011920929\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# Extracting training and validation metrics from history object\n",
        "train_accuracy = history.history['accuracy']\n",
        "val_accuracy = history.history['val_accuracy']\n",
        "train_loss = history.history['loss']\n",
        "val_loss = history.history['val_loss']\n",
        "\n",
        "# Extracting epochs\n",
        "epochs_list = list(range(1, len(train_accuracy) + 1))\n",
        "\n",
        "# Define colors for training and validation lines\n",
        "train_color = 'red'\n",
        "val_color = 'blue'\n",
        "\n",
        "# Create subplots\n",
        "fig = make_subplots(rows=1, cols=2, subplot_titles=(\"Accuracy\", \"Loss\"))\n",
        "\n",
        "# Add traces for accuracy\n",
        "fig.add_trace(go.Scatter(x=epochs_list, y=train_accuracy, mode='lines', name='Training accuracy', line=dict(color=train_color)), row=1, col=1)\n",
        "fig.add_trace(go.Scatter(x=epochs_list, y=val_accuracy, mode='lines', name='Validation accuracy', line=dict(color=val_color)), row=1, col=1)\n",
        "\n",
        "# Add traces for loss\n",
        "fig.add_trace(go.Scatter(x=epochs_list, y=train_loss, mode='lines', name='Training loss', line=dict(color=train_color)), row=1, col=2)\n",
        "fig.add_trace(go.Scatter(x=epochs_list, y=val_loss, mode='lines', name='Validation loss', line=dict(color=val_color)), row=1, col=2)\n",
        "\n",
        "# Update layout\n",
        "fig.update_layout(title_text=\"ResNet50 Training and Validation Metrics Over Epochs\", title_x=0.5)\n",
        "fig.update_xaxes(title_text=\"Epochs\", row=1, col=1)\n",
        "fig.update_xaxes(title_text=\"Epochs\", row=1, col=2)\n",
        "fig.update_yaxes(title_text=\"Accuracy\", row=1, col=1)\n",
        "fig.update_yaxes(title_text=\"Loss\", row=1, col=2)\n",
        "\n",
        "# Show plot\n",
        "fig.show()\n"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 542
        },
        "id": "myLstFrks_s4",
        "outputId": "9471424b-bcba-4c53-918e-34f6b91a98b0"
      },
      "execution_count": 20,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<html>\n",
              "<head><meta charset=\"utf-8\" /></head>\n",
              "<body>\n",
              "    <div>            <script src=\"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_SVG\"></script><script type=\"text/javascript\">if (window.MathJax && window.MathJax.Hub && window.MathJax.Hub.Config) {window.MathJax.Hub.Config({SVG: {font: \"STIX-Web\"}});}</script>                <script type=\"text/javascript\">window.PlotlyConfig = {MathJaxConfig: 'local'};</script>\n",
              "        <script charset=\"utf-8\" src=\"https://cdn.plot.ly/plotly-2.24.1.min.js\"></script>                <div id=\"bbed5b7c-fcc7-4a11-83e3-03ac4c930c88\" class=\"plotly-graph-div\" style=\"height:525px; width:100%;\"></div>            <script type=\"text/javascript\">                                    window.PLOTLYENV=window.PLOTLYENV || {};                                    if (document.getElementById(\"bbed5b7c-fcc7-4a11-83e3-03ac4c930c88\")) {                    Plotly.newPlot(                        \"bbed5b7c-fcc7-4a11-83e3-03ac4c930c88\",                        [{\"line\":{\"color\":\"red\"},\"mode\":\"lines\",\"name\":\"Training accuracy\",\"x\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],\"y\":[0.5475543737411499,0.7071823477745056,0.6850828528404236,0.7237569093704224,0.708563506603241,0.7292817831039429,0.7237569093704224,0.7292817831039429,0.7182320356369019,0.6795580387115479,0.7168508172035217,0.7279005646705627,0.7265193462371826,0.7458563446998596,0.748641312122345,0.6961326003074646,0.7486187815666199,0.7430939078330994,0.7279005646705627,0.7154695987701416],\"type\":\"scatter\",\"xaxis\":\"x\",\"yaxis\":\"y\"},{\"line\":{\"color\":\"blue\"},\"mode\":\"lines\",\"name\":\"Validation accuracy\",\"x\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],\"y\":[0.5874999761581421,0.6000000238418579,0.6187499761581421,0.5375000238418579,0.699999988079071,0.6625000238418579,0.675000011920929,0.637499988079071,0.6812499761581421,0.512499988079071,0.5062500238418579,0.6312500238418579,0.6625000238418579,0.5375000238418579,0.612500011920929,0.612500011920929,0.5687500238418579,0.668749988079071,0.6812499761581421,0.6000000238418579],\"type\":\"scatter\",\"xaxis\":\"x\",\"yaxis\":\"y\"},{\"line\":{\"color\":\"red\"},\"mode\":\"lines\",\"name\":\"Training loss\",\"x\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],\"y\":[0.7139996290206909,0.5827590227127075,0.5586543083190918,0.5377423763275146,0.5267736315727234,0.5164549350738525,0.5318405032157898,0.5121475458145142,0.5241500735282898,0.573957085609436,0.5350342988967896,0.510384202003479,0.512778639793396,0.5060214996337891,0.48827415704727173,0.5337952375411987,0.5038101673126221,0.5169021487236023,0.5290825963020325,0.5144693851470947],\"type\":\"scatter\",\"xaxis\":\"x2\",\"yaxis\":\"y2\"},{\"line\":{\"color\":\"blue\"},\"mode\":\"lines\",\"name\":\"Validation loss\",\"x\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],\"y\":[0.6118497848510742,0.6098122596740723,0.6142648458480835,0.70820152759552,0.5553728342056274,0.6009465456008911,0.5673891305923462,0.6392059326171875,0.5962756872177124,0.8757378458976746,0.8928291201591492,0.6556007266044617,0.6105101704597473,0.7971845865249634,0.7278158068656921,0.7335273623466492,0.7860577702522278,0.5684114694595337,0.60612553358078,0.7318533062934875],\"type\":\"scatter\",\"xaxis\":\"x2\",\"yaxis\":\"y2\"}],                        {\"template\":{\"data\":{\"histogram2dcontour\":[{\"type\":\"histogram2dcontour\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"choropleth\":[{\"type\":\"choropleth\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}],\"histogram2d\":[{\"type\":\"histogram2d\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"heatmap\":[{\"type\":\"heatmap\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"heatmapgl\":[{\"type\":\"heatmapgl\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"contourcarpet\":[{\"type\":\"contourcarpet\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}],\"contour\":[{\"type\":\"contour\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"surface\":[{\"type\":\"surface\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"mesh3d\":[{\"type\":\"mesh3d\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}],\"scatter\":[{\"fillpattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2},\"type\":\"scatter\"}],\"parcoords\":[{\"type\":\"parcoords\",\"line\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatterpolargl\":[{\"type\":\"scatterpolargl\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"bar\":[{\"error_x\":{\"color\":\"#2a3f5f\"},\"error_y\":{\"color\":\"#2a3f5f\"},\"marker\":{\"line\":{\"color\":\"#E5ECF6\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"bar\"}],\"scattergeo\":[{\"type\":\"scattergeo\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatterpolar\":[{\"type\":\"scatterpolar\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"histogram\":[{\"marker\":{\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"histogram\"}],\"scattergl\":[{\"type\":\"scattergl\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatter3d\":[{\"type\":\"scatter3d\",\"line\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scattermapbox\":[{\"type\":\"scattermapbox\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatterternary\":[{\"type\":\"scatterternary\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scattercarpet\":[{\"type\":\"scattercarpet\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"carpet\":[{\"aaxis\":{\"endlinecolor\":\"#2a3f5f\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"minorgridcolor\":\"white\",\"startlinecolor\":\"#2a3f5f\"},\"baxis\":{\"endlinecolor\":\"#2a3f5f\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"minorgridcolor\":\"white\",\"startlinecolor\":\"#2a3f5f\"},\"type\":\"carpet\"}],\"table\":[{\"cells\":{\"fill\":{\"color\":\"#EBF0F8\"},\"line\":{\"color\":\"white\"}},\"header\":{\"fill\":{\"color\":\"#C8D4E3\"},\"line\":{\"color\":\"white\"}},\"type\":\"table\"}],\"barpolar\":[{\"marker\":{\"line\":{\"color\":\"#E5ECF6\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"barpolar\"}],\"pie\":[{\"automargin\":true,\"type\":\"pie\"}]},\"layout\":{\"autotypenumbers\":\"strict\",\"colorway\":[\"#636efa\",\"#EF553B\",\"#00cc96\",\"#ab63fa\",\"#FFA15A\",\"#19d3f3\",\"#FF6692\",\"#B6E880\",\"#FF97FF\",\"#FECB52\"],\"font\":{\"color\":\"#2a3f5f\"},\"hovermode\":\"closest\",\"hoverlabel\":{\"align\":\"left\"},\"paper_bgcolor\":\"white\",\"plot_bgcolor\":\"#E5ECF6\",\"polar\":{\"bgcolor\":\"#E5ECF6\",\"angularaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"},\"radialaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"}},\"ternary\":{\"bgcolor\":\"#E5ECF6\",\"aaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"},\"baxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"},\"caxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"}},\"coloraxis\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"colorscale\":{\"sequential\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"sequentialminus\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"diverging\":[[0,\"#8e0152\"],[0.1,\"#c51b7d\"],[0.2,\"#de77ae\"],[0.3,\"#f1b6da\"],[0.4,\"#fde0ef\"],[0.5,\"#f7f7f7\"],[0.6,\"#e6f5d0\"],[0.7,\"#b8e186\"],[0.8,\"#7fbc41\"],[0.9,\"#4d9221\"],[1,\"#276419\"]]},\"xaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\",\"title\":{\"standoff\":15},\"zerolinecolor\":\"white\",\"automargin\":true,\"zerolinewidth\":2},\"yaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\",\"title\":{\"standoff\":15},\"zerolinecolor\":\"white\",\"automargin\":true,\"zerolinewidth\":2},\"scene\":{\"xaxis\":{\"backgroundcolor\":\"#E5ECF6\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"white\",\"gridwidth\":2},\"yaxis\":{\"backgroundcolor\":\"#E5ECF6\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"white\",\"gridwidth\":2},\"zaxis\":{\"backgroundcolor\":\"#E5ECF6\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"white\",\"gridwidth\":2}},\"shapedefaults\":{\"line\":{\"color\":\"#2a3f5f\"}},\"annotationdefaults\":{\"arrowcolor\":\"#2a3f5f\",\"arrowhead\":0,\"arrowwidth\":1},\"geo\":{\"bgcolor\":\"white\",\"landcolor\":\"#E5ECF6\",\"subunitcolor\":\"white\",\"showland\":true,\"showlakes\":true,\"lakecolor\":\"white\"},\"title\":{\"x\":0.05},\"mapbox\":{\"style\":\"light\"}}},\"xaxis\":{\"anchor\":\"y\",\"domain\":[0.0,0.45],\"title\":{\"text\":\"Epochs\"}},\"yaxis\":{\"anchor\":\"x\",\"domain\":[0.0,1.0],\"title\":{\"text\":\"Accuracy\"}},\"xaxis2\":{\"anchor\":\"y2\",\"domain\":[0.55,1.0],\"title\":{\"text\":\"Epochs\"}},\"yaxis2\":{\"anchor\":\"x2\",\"domain\":[0.0,1.0],\"title\":{\"text\":\"Loss\"}},\"annotations\":[{\"font\":{\"size\":16},\"showarrow\":false,\"text\":\"Accuracy\",\"x\":0.225,\"xanchor\":\"center\",\"xref\":\"paper\",\"y\":1.0,\"yanchor\":\"bottom\",\"yref\":\"paper\"},{\"font\":{\"size\":16},\"showarrow\":false,\"text\":\"Loss\",\"x\":0.775,\"xanchor\":\"center\",\"xref\":\"paper\",\"y\":1.0,\"yanchor\":\"bottom\",\"yref\":\"paper\"}],\"title\":{\"text\":\"ResNet50 Training and Validation Metrics Over Epochs\",\"x\":0.5}},                        {\"responsive\": true}                    ).then(function(){\n",
              "                            \n",
              "var gd = document.getElementById('bbed5b7c-fcc7-4a11-83e3-03ac4c930c88');\n",
              "var x = new MutationObserver(function (mutations, observer) {{\n",
              "        var display = window.getComputedStyle(gd).display;\n",
              "        if (!display || display === 'none') {{\n",
              "            console.log([gd, 'removed!']);\n",
              "            Plotly.purge(gd);\n",
              "            observer.disconnect();\n",
              "        }}\n",
              "}});\n",
              "\n",
              "// Listen for the removal of the full notebook cells\n",
              "var notebookContainer = gd.closest('#notebook-container');\n",
              "if (notebookContainer) {{\n",
              "    x.observe(notebookContainer, {childList: true});\n",
              "}}\n",
              "\n",
              "// Listen for the clearing of the current output cell\n",
              "var outputEl = gd.closest('.output');\n",
              "if (outputEl) {{\n",
              "    x.observe(outputEl, {childList: true});\n",
              "}}\n",
              "\n",
              "                        })                };                            </script>        </div>\n",
              "</body>\n",
              "</html>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "from tensorflow.keras.callbacks import EarlyStopping, ReduceLROnPlateau\n",
        "\n",
        "base_model = ResNet50(weights='imagenet', include_top=False, input_shape=(img_width, img_height, 3))\n",
        "\n",
        "# Unfreeze some top layers for fine-tuning\n",
        "for layer in base_model.layers[-10:]:\n",
        "    layer.trainable = True\n",
        "\n",
        "# Add regularization (e.g., dropout) to custom classification layers\n",
        "model = Sequential([\n",
        "    base_model,\n",
        "    GlobalAveragePooling2D(),\n",
        "    Dense(256, activation='relu'),\n",
        "    Dropout(0.5),  # Add dropout layer\n",
        "    Dense(1, activation='sigmoid')\n",
        "])\n",
        "\n",
        "# Implement early stopping and learning rate reduction\n",
        "early_stopping = EarlyStopping(patience=3, restore_best_weights=True)\n",
        "reduce_lr = ReduceLROnPlateau(factor=0.2, patience=2)\n",
        "\n",
        "# Compile the model with a lower initial learning rate\n",
        "model.compile(optimizer=Adam(lr=0.001),  # Lower learning rate\n",
        "              loss='binary_crossentropy',\n",
        "              metrics=['accuracy'])\n",
        "\n",
        "# Train the model with augmented data\n",
        "history = model.fit(train_generator,\n",
        "                    steps_per_epoch=train_generator.samples // batch_size,\n",
        "                    epochs=20,  # Increase epochs\n",
        "                    validation_data=val_generator,\n",
        "                    validation_steps=val_generator.samples // batch_size,\n",
        "                    callbacks=[early_stopping, reduce_lr])  # Add callbacks for early stopping and reducing LR\n"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "mQQxrL0wulrz",
        "outputId": "0b07eac1-dde3-4d8c-ac0e-5f36fbce61d3"
      },
      "execution_count": 22,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "WARNING:absl:`lr` is deprecated in Keras optimizer, please use `learning_rate` or use the legacy optimizer, e.g.,tf.keras.optimizers.legacy.Adam.\n"
          ]
        },
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Epoch 1/20\n",
            "23/23 [==============================] - 63s 1s/step - loss: 0.6234 - accuracy: 0.7113 - val_loss: 14227.4004 - val_accuracy: 0.5000 - lr: 0.0010\n",
            "Epoch 2/20\n",
            "23/23 [==============================] - 32s 1s/step - loss: 0.3938 - accuracy: 0.8232 - val_loss: 17313.8398 - val_accuracy: 0.4938 - lr: 0.0010\n",
            "Epoch 3/20\n",
            "23/23 [==============================] - 28s 1s/step - loss: 0.3588 - accuracy: 0.8508 - val_loss: 97.4371 - val_accuracy: 0.5000 - lr: 0.0010\n",
            "Epoch 4/20\n",
            "23/23 [==============================] - 29s 1s/step - loss: 0.3532 - accuracy: 0.8425 - val_loss: 0.7302 - val_accuracy: 0.5063 - lr: 0.0010\n",
            "Epoch 5/20\n",
            "23/23 [==============================] - 30s 1s/step - loss: 0.3369 - accuracy: 0.8508 - val_loss: 0.8140 - val_accuracy: 0.5063 - lr: 0.0010\n",
            "Epoch 6/20\n",
            "23/23 [==============================] - 28s 1s/step - loss: 0.3462 - accuracy: 0.8536 - val_loss: 0.7137 - val_accuracy: 0.5000 - lr: 0.0010\n",
            "Epoch 7/20\n",
            "23/23 [==============================] - 28s 1s/step - loss: 0.3419 - accuracy: 0.8439 - val_loss: 0.7015 - val_accuracy: 0.5063 - lr: 0.0010\n",
            "Epoch 8/20\n",
            "23/23 [==============================] - 29s 1s/step - loss: 0.3268 - accuracy: 0.8550 - val_loss: 1.0687 - val_accuracy: 0.4938 - lr: 0.0010\n",
            "Epoch 9/20\n",
            "23/23 [==============================] - 28s 1s/step - loss: 0.3039 - accuracy: 0.8660 - val_loss: 4.6653 - val_accuracy: 0.5000 - lr: 0.0010\n",
            "Epoch 10/20\n",
            "23/23 [==============================] - 28s 1s/step - loss: 0.3157 - accuracy: 0.8674 - val_loss: 6.6413 - val_accuracy: 0.5000 - lr: 2.0000e-04\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# Extracting training and validation metrics from history object\n",
        "train_accuracy = history.history['accuracy']\n",
        "val_accuracy = history.history['val_accuracy']\n",
        "train_loss = history.history['loss']\n",
        "val_loss = history.history['val_loss']\n",
        "\n",
        "# Extracting epochs\n",
        "epochs_list = list(range(1, len(train_accuracy) + 1))\n",
        "\n",
        "# Define colors for training and validation lines\n",
        "train_color = 'red'\n",
        "val_color = 'blue'\n",
        "\n",
        "# Create subplots\n",
        "fig = make_subplots(rows=1, cols=2, subplot_titles=(\"Accuracy\", \"Loss\"))\n",
        "\n",
        "# Add traces for accuracy\n",
        "fig.add_trace(go.Scatter(x=epochs_list, y=train_accuracy, mode='lines', name='Training accuracy', line=dict(color=train_color)), row=1, col=1)\n",
        "fig.add_trace(go.Scatter(x=epochs_list, y=val_accuracy, mode='lines', name='Validation accuracy', line=dict(color=val_color)), row=1, col=1)\n",
        "\n",
        "# Add traces for loss\n",
        "fig.add_trace(go.Scatter(x=epochs_list, y=train_loss, mode='lines', name='Training loss', line=dict(color=train_color)), row=1, col=2)\n",
        "fig.add_trace(go.Scatter(x=epochs_list, y=val_loss, mode='lines', name='Validation loss', line=dict(color=val_color)), row=1, col=2)\n",
        "\n",
        "# Update layout\n",
        "fig.update_layout(title_text=\"ResNet50 Training and Validation Metrics Over Epochs (wtih early stopping and reducing learning rate)\", title_x=0.5)\n",
        "fig.update_xaxes(title_text=\"Epochs\", row=1, col=1)\n",
        "fig.update_xaxes(title_text=\"Epochs\", row=1, col=2)\n",
        "fig.update_yaxes(title_text=\"Accuracy\", row=1, col=1)\n",
        "fig.update_yaxes(title_text=\"Loss\", row=1, col=2)\n",
        "\n",
        "# Show plot\n",
        "fig.show()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 542
        },
        "id": "mY4L4eeRTyS7",
        "outputId": "171455e6-2f4e-4508-f4a8-8975358fa06d"
      },
      "execution_count": 30,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<html>\n",
              "<head><meta charset=\"utf-8\" /></head>\n",
              "<body>\n",
              "    <div>            <script src=\"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_SVG\"></script><script type=\"text/javascript\">if (window.MathJax && window.MathJax.Hub && window.MathJax.Hub.Config) {window.MathJax.Hub.Config({SVG: {font: \"STIX-Web\"}});}</script>                <script type=\"text/javascript\">window.PlotlyConfig = {MathJaxConfig: 'local'};</script>\n",
              "        <script charset=\"utf-8\" src=\"https://cdn.plot.ly/plotly-2.24.1.min.js\"></script>                <div id=\"5fdbd3e6-cf3f-4f7b-b768-b030d6a00cb0\" class=\"plotly-graph-div\" style=\"height:525px; width:100%;\"></div>            <script type=\"text/javascript\">                                    window.PLOTLYENV=window.PLOTLYENV || {};                                    if (document.getElementById(\"5fdbd3e6-cf3f-4f7b-b768-b030d6a00cb0\")) {                    Plotly.newPlot(                        \"5fdbd3e6-cf3f-4f7b-b768-b030d6a00cb0\",                        [{\"line\":{\"color\":\"red\"},\"mode\":\"lines\",\"name\":\"Training accuracy\",\"x\":[1,2,3,4,5,6,7,8,9,10],\"y\":[0.7113259434700012,0.8232043981552124,0.8508287072181702,0.8425414562225342,0.8508287072181702,0.8535911440849304,0.8439226746559143,0.8549723625183105,0.8660221099853516,0.8674033284187317],\"type\":\"scatter\",\"xaxis\":\"x\",\"yaxis\":\"y\"},{\"line\":{\"color\":\"blue\"},\"mode\":\"lines\",\"name\":\"Validation accuracy\",\"x\":[1,2,3,4,5,6,7,8,9,10],\"y\":[0.5,0.4937500059604645,0.5,0.5062500238418579,0.5062500238418579,0.5,0.5062500238418579,0.4937500059604645,0.5,0.5],\"type\":\"scatter\",\"xaxis\":\"x\",\"yaxis\":\"y\"},{\"line\":{\"color\":\"red\"},\"mode\":\"lines\",\"name\":\"Training loss\",\"x\":[1,2,3,4,5,6,7,8,9,10],\"y\":[0.623443067073822,0.3937567472457886,0.3588305413722992,0.353164941072464,0.3368547260761261,0.34615880250930786,0.3419380486011505,0.32679349184036255,0.30385735630989075,0.31567588448524475],\"type\":\"scatter\",\"xaxis\":\"x2\",\"yaxis\":\"y2\"},{\"line\":{\"color\":\"blue\"},\"mode\":\"lines\",\"name\":\"Validation loss\",\"x\":[1,2,3,4,5,6,7,8,9,10],\"y\":[14227.400390625,17313.83984375,97.43710327148438,0.7302473783493042,0.8139657974243164,0.7137237787246704,0.7015279531478882,1.0687196254730225,4.665268898010254,6.641312599182129],\"type\":\"scatter\",\"xaxis\":\"x2\",\"yaxis\":\"y2\"}],                        {\"template\":{\"data\":{\"histogram2dcontour\":[{\"type\":\"histogram2dcontour\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"choropleth\":[{\"type\":\"choropleth\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}],\"histogram2d\":[{\"type\":\"histogram2d\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"heatmap\":[{\"type\":\"heatmap\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"heatmapgl\":[{\"type\":\"heatmapgl\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"contourcarpet\":[{\"type\":\"contourcarpet\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}],\"contour\":[{\"type\":\"contour\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"surface\":[{\"type\":\"surface\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"mesh3d\":[{\"type\":\"mesh3d\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}],\"scatter\":[{\"fillpattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2},\"type\":\"scatter\"}],\"parcoords\":[{\"type\":\"parcoords\",\"line\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatterpolargl\":[{\"type\":\"scatterpolargl\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"bar\":[{\"error_x\":{\"color\":\"#2a3f5f\"},\"error_y\":{\"color\":\"#2a3f5f\"},\"marker\":{\"line\":{\"color\":\"#E5ECF6\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"bar\"}],\"scattergeo\":[{\"type\":\"scattergeo\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatterpolar\":[{\"type\":\"scatterpolar\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"histogram\":[{\"marker\":{\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"histogram\"}],\"scattergl\":[{\"type\":\"scattergl\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatter3d\":[{\"type\":\"scatter3d\",\"line\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scattermapbox\":[{\"type\":\"scattermapbox\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatterternary\":[{\"type\":\"scatterternary\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scattercarpet\":[{\"type\":\"scattercarpet\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"carpet\":[{\"aaxis\":{\"endlinecolor\":\"#2a3f5f\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"minorgridcolor\":\"white\",\"startlinecolor\":\"#2a3f5f\"},\"baxis\":{\"endlinecolor\":\"#2a3f5f\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"minorgridcolor\":\"white\",\"startlinecolor\":\"#2a3f5f\"},\"type\":\"carpet\"}],\"table\":[{\"cells\":{\"fill\":{\"color\":\"#EBF0F8\"},\"line\":{\"color\":\"white\"}},\"header\":{\"fill\":{\"color\":\"#C8D4E3\"},\"line\":{\"color\":\"white\"}},\"type\":\"table\"}],\"barpolar\":[{\"marker\":{\"line\":{\"color\":\"#E5ECF6\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"barpolar\"}],\"pie\":[{\"automargin\":true,\"type\":\"pie\"}]},\"layout\":{\"autotypenumbers\":\"strict\",\"colorway\":[\"#636efa\",\"#EF553B\",\"#00cc96\",\"#ab63fa\",\"#FFA15A\",\"#19d3f3\",\"#FF6692\",\"#B6E880\",\"#FF97FF\",\"#FECB52\"],\"font\":{\"color\":\"#2a3f5f\"},\"hovermode\":\"closest\",\"hoverlabel\":{\"align\":\"left\"},\"paper_bgcolor\":\"white\",\"plot_bgcolor\":\"#E5ECF6\",\"polar\":{\"bgcolor\":\"#E5ECF6\",\"angularaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"},\"radialaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"}},\"ternary\":{\"bgcolor\":\"#E5ECF6\",\"aaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"},\"baxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"},\"caxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"}},\"coloraxis\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"colorscale\":{\"sequential\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"sequentialminus\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"diverging\":[[0,\"#8e0152\"],[0.1,\"#c51b7d\"],[0.2,\"#de77ae\"],[0.3,\"#f1b6da\"],[0.4,\"#fde0ef\"],[0.5,\"#f7f7f7\"],[0.6,\"#e6f5d0\"],[0.7,\"#b8e186\"],[0.8,\"#7fbc41\"],[0.9,\"#4d9221\"],[1,\"#276419\"]]},\"xaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\",\"title\":{\"standoff\":15},\"zerolinecolor\":\"white\",\"automargin\":true,\"zerolinewidth\":2},\"yaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\",\"title\":{\"standoff\":15},\"zerolinecolor\":\"white\",\"automargin\":true,\"zerolinewidth\":2},\"scene\":{\"xaxis\":{\"backgroundcolor\":\"#E5ECF6\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"white\",\"gridwidth\":2},\"yaxis\":{\"backgroundcolor\":\"#E5ECF6\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"white\",\"gridwidth\":2},\"zaxis\":{\"backgroundcolor\":\"#E5ECF6\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"white\",\"gridwidth\":2}},\"shapedefaults\":{\"line\":{\"color\":\"#2a3f5f\"}},\"annotationdefaults\":{\"arrowcolor\":\"#2a3f5f\",\"arrowhead\":0,\"arrowwidth\":1},\"geo\":{\"bgcolor\":\"white\",\"landcolor\":\"#E5ECF6\",\"subunitcolor\":\"white\",\"showland\":true,\"showlakes\":true,\"lakecolor\":\"white\"},\"title\":{\"x\":0.05},\"mapbox\":{\"style\":\"light\"}}},\"xaxis\":{\"anchor\":\"y\",\"domain\":[0.0,0.45],\"title\":{\"text\":\"Epochs\"}},\"yaxis\":{\"anchor\":\"x\",\"domain\":[0.0,1.0],\"title\":{\"text\":\"Accuracy\"}},\"xaxis2\":{\"anchor\":\"y2\",\"domain\":[0.55,1.0],\"title\":{\"text\":\"Epochs\"}},\"yaxis2\":{\"anchor\":\"x2\",\"domain\":[0.0,1.0],\"title\":{\"text\":\"Loss\"}},\"annotations\":[{\"font\":{\"size\":16},\"showarrow\":false,\"text\":\"Accuracy\",\"x\":0.225,\"xanchor\":\"center\",\"xref\":\"paper\",\"y\":1.0,\"yanchor\":\"bottom\",\"yref\":\"paper\"},{\"font\":{\"size\":16},\"showarrow\":false,\"text\":\"Loss\",\"x\":0.775,\"xanchor\":\"center\",\"xref\":\"paper\",\"y\":1.0,\"yanchor\":\"bottom\",\"yref\":\"paper\"}],\"title\":{\"text\":\"ResNet50 Training and Validation Metrics Over Epochs (wtih early stopping and reducing learning rate)\",\"x\":0.5}},                        {\"responsive\": true}                    ).then(function(){\n",
              "                            \n",
              "var gd = document.getElementById('5fdbd3e6-cf3f-4f7b-b768-b030d6a00cb0');\n",
              "var x = new MutationObserver(function (mutations, observer) {{\n",
              "        var display = window.getComputedStyle(gd).display;\n",
              "        if (!display || display === 'none') {{\n",
              "            console.log([gd, 'removed!']);\n",
              "            Plotly.purge(gd);\n",
              "            observer.disconnect();\n",
              "        }}\n",
              "}});\n",
              "\n",
              "// Listen for the removal of the full notebook cells\n",
              "var notebookContainer = gd.closest('#notebook-container');\n",
              "if (notebookContainer) {{\n",
              "    x.observe(notebookContainer, {childList: true});\n",
              "}}\n",
              "\n",
              "// Listen for the clearing of the current output cell\n",
              "var outputEl = gd.closest('.output');\n",
              "if (outputEl) {{\n",
              "    x.observe(outputEl, {childList: true});\n",
              "}}\n",
              "\n",
              "                        })                };                            </script>        </div>\n",
              "</body>\n",
              "</html>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "# ResNet100 Model\n"
      ],
      "metadata": {
        "id": "YiuXRk91W0ds"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "from tensorflow.keras.applications import ResNet101\n",
        "\n",
        "# Set random seed for reproducibility\n",
        "np.random.seed(42)\n",
        "tf.random.set_seed(42)\n",
        "\n",
        "# Define data directories\n",
        "train_dir = \"/content/train\"\n",
        "val_dir = \"/content/val\"\n",
        "test_dir = \"/content/test\"\n",
        "\n",
        "# Define image dimensions\n",
        "img_width, img_height = 224, 224\n",
        "\n",
        "# Define batch size\n",
        "batch_size = 32\n",
        "\n",
        "# Data preprocessing and augmentation\n",
        "train_datagen = ImageDataGenerator(rescale=1./255,\n",
        "                                   rotation_range=15,\n",
        "                                   width_shift_range=0.1,\n",
        "                                   height_shift_range=0.1,\n",
        "                                   shear_range=0.1,\n",
        "                                   zoom_range=0.1,\n",
        "                                   horizontal_flip=True,\n",
        "                                   fill_mode='nearest')\n",
        "\n",
        "val_datagen = ImageDataGenerator(rescale=1./255)\n",
        "\n",
        "# Prepare data generators\n",
        "train_generator = train_datagen.flow_from_directory(train_dir,\n",
        "                                                    target_size=(img_width, img_height),\n",
        "                                                    batch_size=batch_size,\n",
        "                                                    class_mode='binary')\n",
        "\n",
        "val_generator = val_datagen.flow_from_directory(val_dir,\n",
        "                                                target_size=(img_width, img_height),\n",
        "                                                batch_size=batch_size,\n",
        "                                                class_mode='binary')\n",
        "\n",
        "test_generator = val_datagen.flow_from_directory(test_dir,\n",
        "                                                 target_size=(img_width, img_height),\n",
        "                                                 batch_size=batch_size,\n",
        "                                                 class_mode='binary',\n",
        "                                                 shuffle=False)\n",
        "\n",
        "# Load the pre-trained ResNet101 model without the top classification layer\n",
        "base_model = ResNet101(weights='imagenet', include_top=False, input_shape=(img_width, img_height, 3))\n",
        "\n",
        "# Freeze the base model layers\n",
        "for layer in base_model.layers:\n",
        "    layer.trainable = False\n",
        "\n",
        "# Add custom classification layers on top of ResNet101\n",
        "model = Sequential([\n",
        "    base_model,\n",
        "    GlobalAveragePooling2D(),\n",
        "    Dense(256, activation='relu'),\n",
        "    Dense(1, activation='sigmoid')\n",
        "])\n",
        "\n",
        "# Compile the model\n",
        "model.compile(optimizer='adam',\n",
        "              loss='binary_crossentropy',\n",
        "              metrics=['accuracy'])\n",
        "\n",
        "# Train the model\n",
        "history = model.fit(train_generator,\n",
        "                    steps_per_epoch=train_generator.samples // batch_size,\n",
        "                    epochs=20,\n",
        "                    validation_data=val_generator,\n",
        "                    validation_steps=val_generator.samples // batch_size)\n",
        "\n",
        "# Evaluate the model on the test data\n",
        "test_loss, test_accuracy100 = model.evaluate(test_generator, steps=test_generator.samples // batch_size)\n",
        "print(\"Test Accuracy:\", test_accuracy100)\n"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "ew9Cu3jxW0Es",
        "outputId": "02fc8434-a393-417b-c99e-b2782c9bf4eb"
      },
      "execution_count": 47,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Found 756 images belonging to 2 classes.\n",
            "Found 162 images belonging to 2 classes.\n",
            "Found 162 images belonging to 2 classes.\n",
            "Epoch 1/20\n",
            "23/23 [==============================] - 46s 2s/step - loss: 0.6651 - accuracy: 0.5870 - val_loss: 0.5979 - val_accuracy: 0.6687\n",
            "Epoch 2/20\n",
            "23/23 [==============================] - 32s 1s/step - loss: 0.5747 - accuracy: 0.6906 - val_loss: 0.5518 - val_accuracy: 0.6750\n",
            "Epoch 3/20\n",
            "23/23 [==============================] - 31s 1s/step - loss: 0.5408 - accuracy: 0.7127 - val_loss: 0.5493 - val_accuracy: 0.7500\n",
            "Epoch 4/20\n",
            "23/23 [==============================] - 28s 1s/step - loss: 0.5402 - accuracy: 0.7196 - val_loss: 0.5121 - val_accuracy: 0.7500\n",
            "Epoch 5/20\n",
            "23/23 [==============================] - 29s 1s/step - loss: 0.5148 - accuracy: 0.7417 - val_loss: 0.5464 - val_accuracy: 0.7437\n",
            "Epoch 6/20\n",
            "23/23 [==============================] - 32s 1s/step - loss: 0.5085 - accuracy: 0.7486 - val_loss: 0.4952 - val_accuracy: 0.7437\n",
            "Epoch 7/20\n",
            "23/23 [==============================] - 28s 1s/step - loss: 0.4867 - accuracy: 0.7652 - val_loss: 0.5695 - val_accuracy: 0.7188\n",
            "Epoch 8/20\n",
            "23/23 [==============================] - 29s 1s/step - loss: 0.5276 - accuracy: 0.7141 - val_loss: 0.6044 - val_accuracy: 0.6687\n",
            "Epoch 9/20\n",
            "23/23 [==============================] - 30s 1s/step - loss: 0.5176 - accuracy: 0.7348 - val_loss: 0.5327 - val_accuracy: 0.7500\n",
            "Epoch 10/20\n",
            "23/23 [==============================] - 30s 1s/step - loss: 0.4871 - accuracy: 0.7707 - val_loss: 0.4918 - val_accuracy: 0.7500\n",
            "Epoch 11/20\n",
            "23/23 [==============================] - 29s 1s/step - loss: 0.4782 - accuracy: 0.7776 - val_loss: 0.4892 - val_accuracy: 0.7688\n",
            "Epoch 12/20\n",
            "23/23 [==============================] - 29s 1s/step - loss: 0.4745 - accuracy: 0.7638 - val_loss: 0.4968 - val_accuracy: 0.7312\n",
            "Epoch 13/20\n",
            "23/23 [==============================] - 30s 1s/step - loss: 0.4774 - accuracy: 0.7776 - val_loss: 0.5143 - val_accuracy: 0.7063\n",
            "Epoch 14/20\n",
            "23/23 [==============================] - 30s 1s/step - loss: 0.4895 - accuracy: 0.7610 - val_loss: 0.5373 - val_accuracy: 0.7500\n",
            "Epoch 15/20\n",
            "23/23 [==============================] - 29s 1s/step - loss: 0.4645 - accuracy: 0.7666 - val_loss: 0.5485 - val_accuracy: 0.7437\n",
            "Epoch 16/20\n",
            "23/23 [==============================] - 31s 1s/step - loss: 0.5003 - accuracy: 0.7390 - val_loss: 0.4979 - val_accuracy: 0.7312\n",
            "Epoch 17/20\n",
            "23/23 [==============================] - 30s 1s/step - loss: 0.4646 - accuracy: 0.7785 - val_loss: 0.4877 - val_accuracy: 0.7937\n",
            "Epoch 18/20\n",
            "23/23 [==============================] - 30s 1s/step - loss: 0.4773 - accuracy: 0.7597 - val_loss: 0.6615 - val_accuracy: 0.6562\n",
            "Epoch 19/20\n",
            "23/23 [==============================] - 29s 1s/step - loss: 0.4831 - accuracy: 0.7569 - val_loss: 0.4745 - val_accuracy: 0.7750\n",
            "Epoch 20/20\n",
            "23/23 [==============================] - 30s 1s/step - loss: 0.5171 - accuracy: 0.7155 - val_loss: 0.5553 - val_accuracy: 0.6875\n",
            "5/5 [==============================] - 3s 661ms/step - loss: 0.5942 - accuracy: 0.7000\n",
            "Test Accuracy: 0.699999988079071\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# Extracting training and validation metrics from history object\n",
        "train_accuracy = history.history['accuracy']\n",
        "val_accuracy = history.history['val_accuracy']\n",
        "train_loss = history.history['loss']\n",
        "val_loss = history.history['val_loss']\n",
        "\n",
        "# Extracting epochs\n",
        "epochs_list = list(range(1, len(train_accuracy) + 1))\n",
        "\n",
        "# Define colors for training and validation lines\n",
        "train_color = 'red'\n",
        "val_color = 'blue'\n",
        "\n",
        "# Create subplots\n",
        "fig = make_subplots(rows=1, cols=2, subplot_titles=(\"Accuracy\", \"Loss\"))\n",
        "\n",
        "# Add traces for accuracy\n",
        "fig.add_trace(go.Scatter(x=epochs_list, y=train_accuracy, mode='lines', name='Training accuracy', line=dict(color=train_color)), row=1, col=1)\n",
        "fig.add_trace(go.Scatter(x=epochs_list, y=val_accuracy, mode='lines', name='Validation accuracy', line=dict(color=val_color)), row=1, col=1)\n",
        "\n",
        "# Add traces for loss\n",
        "fig.add_trace(go.Scatter(x=epochs_list, y=train_loss, mode='lines', name='Training loss', line=dict(color=train_color)), row=1, col=2)\n",
        "fig.add_trace(go.Scatter(x=epochs_list, y=val_loss, mode='lines', name='Validation loss', line=dict(color=val_color)), row=1, col=2)\n",
        "\n",
        "# Update layout\n",
        "fig.update_layout(title_text=\"ResNet100 Training and Validation Metrics Over Epochs\", title_x=0.5)\n",
        "fig.update_xaxes(title_text=\"Epochs\", row=1, col=1)\n",
        "fig.update_xaxes(title_text=\"Epochs\", row=1, col=2)\n",
        "fig.update_yaxes(title_text=\"Accuracy\", row=1, col=1)\n",
        "fig.update_yaxes(title_text=\"Loss\", row=1, col=2)\n",
        "\n",
        "# Show plot\n",
        "fig.show()\n"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 542
        },
        "id": "9WBylW1AZEIi",
        "outputId": "61dfe152-b909-4548-ab13-e06240fc0a63"
      },
      "execution_count": 50,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<html>\n",
              "<head><meta charset=\"utf-8\" /></head>\n",
              "<body>\n",
              "    <div>            <script src=\"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_SVG\"></script><script type=\"text/javascript\">if (window.MathJax && window.MathJax.Hub && window.MathJax.Hub.Config) {window.MathJax.Hub.Config({SVG: {font: \"STIX-Web\"}});}</script>                <script type=\"text/javascript\">window.PlotlyConfig = {MathJaxConfig: 'local'};</script>\n",
              "        <script charset=\"utf-8\" src=\"https://cdn.plot.ly/plotly-2.24.1.min.js\"></script>                <div id=\"7c3a2563-4fd1-4880-b77d-2ebc3e23f199\" class=\"plotly-graph-div\" style=\"height:525px; width:100%;\"></div>            <script type=\"text/javascript\">                                    window.PLOTLYENV=window.PLOTLYENV || {};                                    if (document.getElementById(\"7c3a2563-4fd1-4880-b77d-2ebc3e23f199\")) {                    Plotly.newPlot(                        \"7c3a2563-4fd1-4880-b77d-2ebc3e23f199\",                        [{\"line\":{\"color\":\"red\"},\"mode\":\"lines\",\"name\":\"Training accuracy\",\"x\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],\"y\":[0.519336998462677,0.5055248737335205,0.48342540860176086,0.5455800890922546,0.6602209806442261,0.7527624368667603,0.7361878156661987,0.7762430906295776,0.810773491859436,0.8342541456222534,0.841160237789154,0.8245856165885925,0.830110490322113,0.84944748878479,0.8480662703514099,0.841160237789154,0.8535911440849304,0.8259668350219727,0.8563535809516907,0.8618784546852112],\"type\":\"scatter\",\"xaxis\":\"x\",\"yaxis\":\"y\"},{\"line\":{\"color\":\"blue\"},\"mode\":\"lines\",\"name\":\"Validation accuracy\",\"x\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],\"y\":[0.59375,0.5,0.5062500238418579,0.5,0.5,0.5,0.5062500238418579,0.606249988079071,0.5,0.5062500238418579,0.5625,0.5,0.59375,0.5874999761581421,0.543749988079071,0.6937500238418579,0.875,0.731249988079071,0.6812499761581421,0.762499988079071],\"type\":\"scatter\",\"xaxis\":\"x\",\"yaxis\":\"y\"},{\"line\":{\"color\":\"red\"},\"mode\":\"lines\",\"name\":\"Training loss\",\"x\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],\"y\":[0.7151789665222168,0.6955041885375977,0.6946223378181458,0.6901799440383911,0.6165300011634827,0.49523264169692993,0.5118696093559265,0.4658953547477722,0.40447792410850525,0.3583831489086151,0.372563898563385,0.382798433303833,0.357797235250473,0.35774147510528564,0.3399890661239624,0.3472440242767334,0.3567115068435669,0.40472760796546936,0.34402957558631897,0.3256031274795532],\"type\":\"scatter\",\"xaxis\":\"x2\",\"yaxis\":\"y2\"},{\"line\":{\"color\":\"blue\"},\"mode\":\"lines\",\"name\":\"Validation loss\",\"x\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],\"y\":[0.6929856538772583,0.6921688318252563,0.6928836703300476,0.8168094754219055,1.402459740638733,1.8748480081558228,1.4701248407363892,0.8219864964485168,2.3651981353759766,2.464895725250244,1.4484851360321045,1.7197004556655884,1.068715214729309,0.9838064908981323,1.1930936574935913,0.6301901340484619,0.28780436515808105,0.9728773236274719,0.8349654078483582,0.5102987885475159],\"type\":\"scatter\",\"xaxis\":\"x2\",\"yaxis\":\"y2\"}],                        {\"template\":{\"data\":{\"histogram2dcontour\":[{\"type\":\"histogram2dcontour\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"choropleth\":[{\"type\":\"choropleth\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}],\"histogram2d\":[{\"type\":\"histogram2d\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"heatmap\":[{\"type\":\"heatmap\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"heatmapgl\":[{\"type\":\"heatmapgl\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"contourcarpet\":[{\"type\":\"contourcarpet\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}],\"contour\":[{\"type\":\"contour\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"surface\":[{\"type\":\"surface\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"mesh3d\":[{\"type\":\"mesh3d\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}],\"scatter\":[{\"fillpattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2},\"type\":\"scatter\"}],\"parcoords\":[{\"type\":\"parcoords\",\"line\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatterpolargl\":[{\"type\":\"scatterpolargl\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"bar\":[{\"error_x\":{\"color\":\"#2a3f5f\"},\"error_y\":{\"color\":\"#2a3f5f\"},\"marker\":{\"line\":{\"color\":\"#E5ECF6\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"bar\"}],\"scattergeo\":[{\"type\":\"scattergeo\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatterpolar\":[{\"type\":\"scatterpolar\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"histogram\":[{\"marker\":{\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"histogram\"}],\"scattergl\":[{\"type\":\"scattergl\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatter3d\":[{\"type\":\"scatter3d\",\"line\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scattermapbox\":[{\"type\":\"scattermapbox\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatterternary\":[{\"type\":\"scatterternary\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scattercarpet\":[{\"type\":\"scattercarpet\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"carpet\":[{\"aaxis\":{\"endlinecolor\":\"#2a3f5f\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"minorgridcolor\":\"white\",\"startlinecolor\":\"#2a3f5f\"},\"baxis\":{\"endlinecolor\":\"#2a3f5f\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"minorgridcolor\":\"white\",\"startlinecolor\":\"#2a3f5f\"},\"type\":\"carpet\"}],\"table\":[{\"cells\":{\"fill\":{\"color\":\"#EBF0F8\"},\"line\":{\"color\":\"white\"}},\"header\":{\"fill\":{\"color\":\"#C8D4E3\"},\"line\":{\"color\":\"white\"}},\"type\":\"table\"}],\"barpolar\":[{\"marker\":{\"line\":{\"color\":\"#E5ECF6\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"barpolar\"}],\"pie\":[{\"automargin\":true,\"type\":\"pie\"}]},\"layout\":{\"autotypenumbers\":\"strict\",\"colorway\":[\"#636efa\",\"#EF553B\",\"#00cc96\",\"#ab63fa\",\"#FFA15A\",\"#19d3f3\",\"#FF6692\",\"#B6E880\",\"#FF97FF\",\"#FECB52\"],\"font\":{\"color\":\"#2a3f5f\"},\"hovermode\":\"closest\",\"hoverlabel\":{\"align\":\"left\"},\"paper_bgcolor\":\"white\",\"plot_bgcolor\":\"#E5ECF6\",\"polar\":{\"bgcolor\":\"#E5ECF6\",\"angularaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"},\"radialaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"}},\"ternary\":{\"bgcolor\":\"#E5ECF6\",\"aaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"},\"baxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"},\"caxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"}},\"coloraxis\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"colorscale\":{\"sequential\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"sequentialminus\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"diverging\":[[0,\"#8e0152\"],[0.1,\"#c51b7d\"],[0.2,\"#de77ae\"],[0.3,\"#f1b6da\"],[0.4,\"#fde0ef\"],[0.5,\"#f7f7f7\"],[0.6,\"#e6f5d0\"],[0.7,\"#b8e186\"],[0.8,\"#7fbc41\"],[0.9,\"#4d9221\"],[1,\"#276419\"]]},\"xaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\",\"title\":{\"standoff\":15},\"zerolinecolor\":\"white\",\"automargin\":true,\"zerolinewidth\":2},\"yaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\",\"title\":{\"standoff\":15},\"zerolinecolor\":\"white\",\"automargin\":true,\"zerolinewidth\":2},\"scene\":{\"xaxis\":{\"backgroundcolor\":\"#E5ECF6\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"white\",\"gridwidth\":2},\"yaxis\":{\"backgroundcolor\":\"#E5ECF6\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"white\",\"gridwidth\":2},\"zaxis\":{\"backgroundcolor\":\"#E5ECF6\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"white\",\"gridwidth\":2}},\"shapedefaults\":{\"line\":{\"color\":\"#2a3f5f\"}},\"annotationdefaults\":{\"arrowcolor\":\"#2a3f5f\",\"arrowhead\":0,\"arrowwidth\":1},\"geo\":{\"bgcolor\":\"white\",\"landcolor\":\"#E5ECF6\",\"subunitcolor\":\"white\",\"showland\":true,\"showlakes\":true,\"lakecolor\":\"white\"},\"title\":{\"x\":0.05},\"mapbox\":{\"style\":\"light\"}}},\"xaxis\":{\"anchor\":\"y\",\"domain\":[0.0,0.45],\"title\":{\"text\":\"Epochs\"}},\"yaxis\":{\"anchor\":\"x\",\"domain\":[0.0,1.0],\"title\":{\"text\":\"Accuracy\"}},\"xaxis2\":{\"anchor\":\"y2\",\"domain\":[0.55,1.0],\"title\":{\"text\":\"Epochs\"}},\"yaxis2\":{\"anchor\":\"x2\",\"domain\":[0.0,1.0],\"title\":{\"text\":\"Loss\"}},\"annotations\":[{\"font\":{\"size\":16},\"showarrow\":false,\"text\":\"Accuracy\",\"x\":0.225,\"xanchor\":\"center\",\"xref\":\"paper\",\"y\":1.0,\"yanchor\":\"bottom\",\"yref\":\"paper\"},{\"font\":{\"size\":16},\"showarrow\":false,\"text\":\"Loss\",\"x\":0.775,\"xanchor\":\"center\",\"xref\":\"paper\",\"y\":1.0,\"yanchor\":\"bottom\",\"yref\":\"paper\"}],\"title\":{\"text\":\"ResNet100 Training and Validation Metrics Over Epochs\",\"x\":0.5}},                        {\"responsive\": true}                    ).then(function(){\n",
              "                            \n",
              "var gd = document.getElementById('7c3a2563-4fd1-4880-b77d-2ebc3e23f199');\n",
              "var x = new MutationObserver(function (mutations, observer) {{\n",
              "        var display = window.getComputedStyle(gd).display;\n",
              "        if (!display || display === 'none') {{\n",
              "            console.log([gd, 'removed!']);\n",
              "            Plotly.purge(gd);\n",
              "            observer.disconnect();\n",
              "        }}\n",
              "}});\n",
              "\n",
              "// Listen for the removal of the full notebook cells\n",
              "var notebookContainer = gd.closest('#notebook-container');\n",
              "if (notebookContainer) {{\n",
              "    x.observe(notebookContainer, {childList: true});\n",
              "}}\n",
              "\n",
              "// Listen for the clearing of the current output cell\n",
              "var outputEl = gd.closest('.output');\n",
              "if (outputEl) {{\n",
              "    x.observe(outputEl, {childList: true});\n",
              "}}\n",
              "\n",
              "                        })                };                            </script>        </div>\n",
              "</body>\n",
              "</html>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "# Aleksandra's ResNet Model"
      ],
      "metadata": {
        "id": "Jp_BDyi_wAKj"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "def residual_block(x, filters, strides=1, activation='relu'):\n",
        "    shortcut = x\n",
        "    x = Conv2D(filters, kernel_size=(3, 3), strides=strides, padding='same')(x)\n",
        "    x = BatchNormalization()(x)\n",
        "    x = Activation(activation)(x)\n",
        "    x = Conv2D(filters, kernel_size=(3, 3), strides=1, padding='same')(x)\n",
        "    x = BatchNormalization()(x)\n",
        "    if strides != 1 or shortcut.shape[-1] != filters:\n",
        "        shortcut = Conv2D(filters, kernel_size=(1, 1), strides=strides, padding='same')(shortcut)\n",
        "        shortcut = BatchNormalization()(shortcut)\n",
        "    x = Add()([x, shortcut])\n",
        "    x = Activation(activation)(x)\n",
        "    return x\n",
        "\n",
        "def custom_resnet(input_shape, num_classes):\n",
        "    inputs = Input(shape=input_shape)\n",
        "    x = Conv2D(64, kernel_size=(7, 7), strides=2, padding='same')(inputs)\n",
        "    x = BatchNormalization()(x)\n",
        "    x = Activation('relu')(x)\n",
        "    x = residual_block(x, filters=64)\n",
        "    x = residual_block(x, filters=64)\n",
        "    x = residual_block(x, filters=128, strides=2)\n",
        "    x = residual_block(x, filters=128)\n",
        "    x = GlobalAveragePooling2D()(x)\n",
        "    outputs = Dense(num_classes, activation='softmax')(x)\n",
        "    model = tf.keras.Model(inputs, outputs)\n",
        "    return model\n",
        "\n",
        "# Define input shape and number of classes\n",
        "input_shape = (224, 224, 2)\n",
        "num_classes = 2  # Binary classification (normal vs. abnormal)\n",
        "\n",
        "# Create the custom ResNet model\n",
        "model = custom_resnet(input_shape, num_classes)\n",
        "\n",
        "# Compile the model\n",
        "model.compile(optimizer='adam',\n",
        "              loss='sparse_categorical_crossentropy',\n",
        "              metrics=['accuracy'])\n",
        "\n",
        "# Print model summary\n",
        "model.summary()\n"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "Akz7nZXyv_Mj",
        "outputId": "1c32ff2c-5555-4591-fdbc-b018c0729fb9"
      },
      "execution_count": 53,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Model: \"model_2\"\n",
            "__________________________________________________________________________________________________\n",
            " Layer (type)                Output Shape                 Param #   Connected to                  \n",
            "==================================================================================================\n",
            " input_10 (InputLayer)       [(None, 224, 224, 2)]        0         []                            \n",
            "                                                                                                  \n",
            " conv2d_40 (Conv2D)          (None, 112, 112, 64)         6336      ['input_10[0][0]']            \n",
            "                                                                                                  \n",
            " batch_normalization_20 (Ba  (None, 112, 112, 64)         256       ['conv2d_40[0][0]']           \n",
            " tchNormalization)                                                                                \n",
            "                                                                                                  \n",
            " activation_18 (Activation)  (None, 112, 112, 64)         0         ['batch_normalization_20[0][0]\n",
            "                                                                    ']                            \n",
            "                                                                                                  \n",
            " conv2d_41 (Conv2D)          (None, 112, 112, 64)         36928     ['activation_18[0][0]']       \n",
            "                                                                                                  \n",
            " batch_normalization_21 (Ba  (None, 112, 112, 64)         256       ['conv2d_41[0][0]']           \n",
            " tchNormalization)                                                                                \n",
            "                                                                                                  \n",
            " activation_19 (Activation)  (None, 112, 112, 64)         0         ['batch_normalization_21[0][0]\n",
            "                                                                    ']                            \n",
            "                                                                                                  \n",
            " conv2d_42 (Conv2D)          (None, 112, 112, 64)         36928     ['activation_19[0][0]']       \n",
            "                                                                                                  \n",
            " batch_normalization_22 (Ba  (None, 112, 112, 64)         256       ['conv2d_42[0][0]']           \n",
            " tchNormalization)                                                                                \n",
            "                                                                                                  \n",
            " add_8 (Add)                 (None, 112, 112, 64)         0         ['batch_normalization_22[0][0]\n",
            "                                                                    ',                            \n",
            "                                                                     'activation_18[0][0]']       \n",
            "                                                                                                  \n",
            " activation_20 (Activation)  (None, 112, 112, 64)         0         ['add_8[0][0]']               \n",
            "                                                                                                  \n",
            " conv2d_43 (Conv2D)          (None, 112, 112, 64)         36928     ['activation_20[0][0]']       \n",
            "                                                                                                  \n",
            " batch_normalization_23 (Ba  (None, 112, 112, 64)         256       ['conv2d_43[0][0]']           \n",
            " tchNormalization)                                                                                \n",
            "                                                                                                  \n",
            " activation_21 (Activation)  (None, 112, 112, 64)         0         ['batch_normalization_23[0][0]\n",
            "                                                                    ']                            \n",
            "                                                                                                  \n",
            " conv2d_44 (Conv2D)          (None, 112, 112, 64)         36928     ['activation_21[0][0]']       \n",
            "                                                                                                  \n",
            " batch_normalization_24 (Ba  (None, 112, 112, 64)         256       ['conv2d_44[0][0]']           \n",
            " tchNormalization)                                                                                \n",
            "                                                                                                  \n",
            " add_9 (Add)                 (None, 112, 112, 64)         0         ['batch_normalization_24[0][0]\n",
            "                                                                    ',                            \n",
            "                                                                     'activation_20[0][0]']       \n",
            "                                                                                                  \n",
            " activation_22 (Activation)  (None, 112, 112, 64)         0         ['add_9[0][0]']               \n",
            "                                                                                                  \n",
            " conv2d_45 (Conv2D)          (None, 56, 56, 128)          73856     ['activation_22[0][0]']       \n",
            "                                                                                                  \n",
            " batch_normalization_25 (Ba  (None, 56, 56, 128)          512       ['conv2d_45[0][0]']           \n",
            " tchNormalization)                                                                                \n",
            "                                                                                                  \n",
            " activation_23 (Activation)  (None, 56, 56, 128)          0         ['batch_normalization_25[0][0]\n",
            "                                                                    ']                            \n",
            "                                                                                                  \n",
            " conv2d_46 (Conv2D)          (None, 56, 56, 128)          147584    ['activation_23[0][0]']       \n",
            "                                                                                                  \n",
            " conv2d_47 (Conv2D)          (None, 56, 56, 128)          8320      ['activation_22[0][0]']       \n",
            "                                                                                                  \n",
            " batch_normalization_26 (Ba  (None, 56, 56, 128)          512       ['conv2d_46[0][0]']           \n",
            " tchNormalization)                                                                                \n",
            "                                                                                                  \n",
            " batch_normalization_27 (Ba  (None, 56, 56, 128)          512       ['conv2d_47[0][0]']           \n",
            " tchNormalization)                                                                                \n",
            "                                                                                                  \n",
            " add_10 (Add)                (None, 56, 56, 128)          0         ['batch_normalization_26[0][0]\n",
            "                                                                    ',                            \n",
            "                                                                     'batch_normalization_27[0][0]\n",
            "                                                                    ']                            \n",
            "                                                                                                  \n",
            " activation_24 (Activation)  (None, 56, 56, 128)          0         ['add_10[0][0]']              \n",
            "                                                                                                  \n",
            " conv2d_48 (Conv2D)          (None, 56, 56, 128)          147584    ['activation_24[0][0]']       \n",
            "                                                                                                  \n",
            " batch_normalization_28 (Ba  (None, 56, 56, 128)          512       ['conv2d_48[0][0]']           \n",
            " tchNormalization)                                                                                \n",
            "                                                                                                  \n",
            " activation_25 (Activation)  (None, 56, 56, 128)          0         ['batch_normalization_28[0][0]\n",
            "                                                                    ']                            \n",
            "                                                                                                  \n",
            " conv2d_49 (Conv2D)          (None, 56, 56, 128)          147584    ['activation_25[0][0]']       \n",
            "                                                                                                  \n",
            " batch_normalization_29 (Ba  (None, 56, 56, 128)          512       ['conv2d_49[0][0]']           \n",
            " tchNormalization)                                                                                \n",
            "                                                                                                  \n",
            " add_11 (Add)                (None, 56, 56, 128)          0         ['batch_normalization_29[0][0]\n",
            "                                                                    ',                            \n",
            "                                                                     'activation_24[0][0]']       \n",
            "                                                                                                  \n",
            " activation_26 (Activation)  (None, 56, 56, 128)          0         ['add_11[0][0]']              \n",
            "                                                                                                  \n",
            " global_average_pooling2d_8  (None, 128)                  0         ['activation_26[0][0]']       \n",
            "  (GlobalAveragePooling2D)                                                                        \n",
            "                                                                                                  \n",
            " dense_26 (Dense)            (None, 2)                    258       ['global_average_pooling2d_8[0\n",
            "                                                                    ][0]']                        \n",
            "                                                                                                  \n",
            "==================================================================================================\n",
            "Total params: 683074 (2.61 MB)\n",
            "Trainable params: 681154 (2.60 MB)\n",
            "Non-trainable params: 1920 (7.50 KB)\n",
            "__________________________________________________________________________________________________\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# Define paths for the new folders that will contain training, testing, and validation sets\n",
        "train_normal_folder = \"/content/train/normal\"\n",
        "train_abnormal_folder = \"/content/train/abnormal\"\n",
        "test_normal_folder = \"/content/test/normal\"\n",
        "test_abnormal_folder = \"/content/test/abnormal\"\n",
        "val_normal_folder = \"/content/val/normal\"\n",
        "val_abnormal_folder = \"/content/val/abnormal\"\n",
        "\n",
        "# Define image dimensions\n",
        "img_width, img_height = 224, 224\n",
        "\n",
        "# Define batch size\n",
        "batch_size = 32\n",
        "\n",
        "# Data preprocessing and augmentation\n",
        "train_datagen = ImageDataGenerator(rescale=1./255,\n",
        "                                   rotation_range=15,\n",
        "                                   width_shift_range=0.1,\n",
        "                                   height_shift_range=0.1,\n",
        "                                   shear_range=0.1,\n",
        "                                   zoom_range=0.1,\n",
        "                                   horizontal_flip=True,\n",
        "                                   fill_mode='nearest')\n",
        "\n",
        "val_datagen = ImageDataGenerator(rescale=1./255)\n",
        "\n",
        "# Prepare data generators\n",
        "train_generator = train_datagen.flow_from_directory(\"/content/train\",\n",
        "                                                    target_size=(img_width, img_height),\n",
        "                                                    batch_size=batch_size,\n",
        "                                                    class_mode='binary')\n",
        "\n",
        "val_generator = val_datagen.flow_from_directory(\"/content/val\",\n",
        "                                                target_size=(img_width, img_height),\n",
        "                                                batch_size=batch_size,\n",
        "                                                class_mode='binary')\n",
        "\n",
        "test_generator = val_datagen.flow_from_directory(\"/content/test\",\n",
        "                                                 target_size=(img_width, img_height),\n",
        "                                                 batch_size=batch_size,\n",
        "                                                 class_mode='binary',\n",
        "                                                 shuffle=False)\n",
        "\n",
        "# Define the CNN model\n",
        "model = Sequential([\n",
        "    Conv2D(32, (3, 3), activation='relu', input_shape=(img_width, img_height, 3)),\n",
        "    MaxPooling2D((2, 2)),\n",
        "    Conv2D(64, (3, 3), activation='relu'),\n",
        "    MaxPooling2D((2, 2)),\n",
        "    Conv2D(128, (3, 3), activation='relu'),\n",
        "    MaxPooling2D((2, 2)),\n",
        "    Conv2D(128, (3, 3), activation='relu'),\n",
        "    MaxPooling2D((2, 2)),\n",
        "    Flatten(),\n",
        "    Dense(512, activation='relu'),\n",
        "    Dropout(0.5),\n",
        "    Dense(1, activation='sigmoid')\n",
        "])\n",
        "\n",
        "# Compile the model\n",
        "model.compile(optimizer='adam',\n",
        "              loss='binary_crossentropy',\n",
        "              metrics=['accuracy'])\n",
        "\n",
        "# Train the model\n",
        "history = model.fit(train_generator,\n",
        "                    steps_per_epoch=train_generator.samples // batch_size,\n",
        "                    epochs=50,\n",
        "                    validation_data=val_generator,\n",
        "                    validation_steps=val_generator.samples // batch_size)\n",
        "\n",
        "# Evaluate the model on the test data\n",
        "test_loss, test_accuracy_mine = model.evaluate(test_generator, steps=test_generator.samples // batch_size)\n",
        "print(\"Test Accuracy:\", test_accuracy_mine)\n"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "EZtBQEkoyXJL",
        "outputId": "424afd7c-8fa4-4a63-898a-646c7947812f"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Found 756 images belonging to 2 classes.\n",
            "Found 162 images belonging to 2 classes.\n",
            "Found 162 images belonging to 2 classes.\n",
            "Epoch 1/50\n",
            "23/23 [==============================] - 30s 1s/step - loss: 0.7546 - accuracy: 0.5152 - val_loss: 0.7129 - val_accuracy: 0.5000\n",
            "Epoch 2/50\n",
            "23/23 [==============================] - 29s 1s/step - loss: 0.6954 - accuracy: 0.4945 - val_loss: 0.6932 - val_accuracy: 0.5000\n",
            "Epoch 3/50\n",
            "23/23 [==============================] - 27s 1s/step - loss: 0.6932 - accuracy: 0.5028 - val_loss: 0.6931 - val_accuracy: 0.5063\n",
            "Epoch 4/50\n",
            "23/23 [==============================] - 26s 1s/step - loss: 0.6932 - accuracy: 0.4862 - val_loss: 0.6932 - val_accuracy: 0.5000\n",
            "Epoch 5/50\n",
            "23/23 [==============================] - 29s 1s/step - loss: 0.6933 - accuracy: 0.4903 - val_loss: 0.6932 - val_accuracy: 0.4938\n",
            "Epoch 6/50\n",
            "23/23 [==============================] - 33s 1s/step - loss: 0.6932 - accuracy: 0.4862 - val_loss: 0.6839 - val_accuracy: 0.6313\n",
            "Epoch 7/50\n",
            "23/23 [==============================] - 27s 1s/step - loss: 0.7067 - accuracy: 0.4903 - val_loss: 0.6932 - val_accuracy: 0.5000\n",
            "Epoch 8/50\n",
            "23/23 [==============================] - 28s 1s/step - loss: 0.6953 - accuracy: 0.4834 - val_loss: 0.6932 - val_accuracy: 0.5000\n",
            "Epoch 9/50\n",
            "23/23 [==============================] - 29s 1s/step - loss: 0.6935 - accuracy: 0.5124 - val_loss: 0.6932 - val_accuracy: 0.5000\n",
            "Epoch 10/50\n",
            "23/23 [==============================] - 27s 1s/step - loss: 0.6933 - accuracy: 0.4959 - val_loss: 0.6932 - val_accuracy: 0.5000\n",
            "Epoch 11/50\n",
            "23/23 [==============================] - 29s 1s/step - loss: 0.6936 - accuracy: 0.4972 - val_loss: 0.6931 - val_accuracy: 0.5063\n",
            "Epoch 12/50\n",
            "23/23 [==============================] - 27s 1s/step - loss: 0.6933 - accuracy: 0.5041 - val_loss: 0.6931 - val_accuracy: 0.5063\n",
            "Epoch 13/50\n",
            "23/23 [==============================] - 34s 1s/step - loss: 0.6933 - accuracy: 0.4890 - val_loss: 0.6932 - val_accuracy: 0.5000\n",
            "Epoch 14/50\n",
            "23/23 [==============================] - 29s 1s/step - loss: 0.6931 - accuracy: 0.5095 - val_loss: 0.6932 - val_accuracy: 0.5000\n",
            "Epoch 15/50\n",
            "23/23 [==============================] - 29s 1s/step - loss: 0.6935 - accuracy: 0.4945 - val_loss: 0.6932 - val_accuracy: 0.5000\n",
            "Epoch 16/50\n",
            "23/23 [==============================] - 27s 1s/step - loss: 0.6935 - accuracy: 0.4558 - val_loss: 0.6932 - val_accuracy: 0.4938\n",
            "Epoch 17/50\n",
            "23/23 [==============================] - 29s 1s/step - loss: 0.6933 - accuracy: 0.4793 - val_loss: 0.6931 - val_accuracy: 0.5063\n",
            "Epoch 18/50\n",
            "23/23 [==============================] - 29s 1s/step - loss: 0.6928 - accuracy: 0.5152 - val_loss: 0.6893 - val_accuracy: 0.5312\n",
            "Epoch 19/50\n",
            "23/23 [==============================] - 29s 1s/step - loss: 0.7520 - accuracy: 0.5124 - val_loss: 0.6932 - val_accuracy: 0.5000\n",
            "Epoch 20/50\n",
            "11/23 [=============>................] - ETA: 10s - loss: 0.6931 - accuracy: 0.4941"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# Extracting training and validation metrics from history object\n",
        "train_accuracy = history.history['accuracy']\n",
        "val_accuracy = history.history['val_accuracy']\n",
        "train_loss = history.history['loss']\n",
        "val_loss = history.history['val_loss']\n",
        "\n",
        "# Extracting epochs\n",
        "epochs_list = list(range(1, len(train_accuracy) + 1))\n",
        "\n",
        "# Define colors for training and validation lines\n",
        "train_color = 'red'\n",
        "val_color = 'blue'\n",
        "\n",
        "# Create subplots\n",
        "fig = make_subplots(rows=1, cols=2, subplot_titles=(\"Accuracy\", \"Loss\"))\n",
        "\n",
        "# Add traces for accuracy\n",
        "fig.add_trace(go.Scatter(x=epochs_list, y=train_accuracy, mode='lines', name='Training accuracy', line=dict(color=train_color)), row=1, col=1)\n",
        "fig.add_trace(go.Scatter(x=epochs_list, y=val_accuracy, mode='lines', name='Validation accuracy', line=dict(color=val_color)), row=1, col=1)\n",
        "\n",
        "# Add traces for loss\n",
        "fig.add_trace(go.Scatter(x=epochs_list, y=train_loss, mode='lines', name='Training loss', line=dict(color=train_color)), row=1, col=2)\n",
        "fig.add_trace(go.Scatter(x=epochs_list, y=val_loss, mode='lines', name='Validation loss', line=dict(color=val_color)), row=1, col=2)\n",
        "\n",
        "# Update layout\n",
        "fig.update_layout(title_text=\"Aleksandra's ResNet Model Training and Validation Metrics Over Epochs\", title_x=0.5)\n",
        "fig.update_xaxes(title_text=\"Epochs\", row=1, col=1)\n",
        "fig.update_xaxes(title_text=\"Epochs\", row=1, col=2)\n",
        "fig.update_yaxes(title_text=\"Accuracy\", row=1, col=1)\n",
        "fig.update_yaxes(title_text=\"Loss\", row=1, col=2)\n",
        "\n",
        "# Show plot\n",
        "fig.show()\n"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 542
        },
        "id": "TatVSDc4WYhj",
        "outputId": "ec891819-cd11-49a3-bed7-deb401802ffe"
      },
      "execution_count": 34,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<html>\n",
              "<head><meta charset=\"utf-8\" /></head>\n",
              "<body>\n",
              "    <div>            <script src=\"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_SVG\"></script><script type=\"text/javascript\">if (window.MathJax && window.MathJax.Hub && window.MathJax.Hub.Config) {window.MathJax.Hub.Config({SVG: {font: \"STIX-Web\"}});}</script>                <script type=\"text/javascript\">window.PlotlyConfig = {MathJaxConfig: 'local'};</script>\n",
              "        <script charset=\"utf-8\" src=\"https://cdn.plot.ly/plotly-2.24.1.min.js\"></script>                <div id=\"e2178ac2-eace-49a1-b596-b6b76dceea3a\" class=\"plotly-graph-div\" style=\"height:525px; width:100%;\"></div>            <script type=\"text/javascript\">                                    window.PLOTLYENV=window.PLOTLYENV || {};                                    if (document.getElementById(\"e2178ac2-eace-49a1-b596-b6b76dceea3a\")) {                    Plotly.newPlot(                        \"e2178ac2-eace-49a1-b596-b6b76dceea3a\",                        [{\"line\":{\"color\":\"red\"},\"mode\":\"lines\",\"name\":\"Training accuracy\",\"x\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],\"y\":[0.5207182168960571,0.48756906390190125,0.5041436553001404,0.4944751262664795,0.4986187815666199,0.4751381278038025,0.5055248737335205,0.5,0.5345304012298584,0.5179557800292969,0.5690608024597168,0.5069060921669006,0.5027624368667603,0.4986187815666199,0.4944751262664795,0.484806627035141,0.5041436553001404,0.5285326242446899,0.5082873106002808,0.5262430906295776],\"type\":\"scatter\",\"xaxis\":\"x\",\"yaxis\":\"y\"},{\"line\":{\"color\":\"blue\"},\"mode\":\"lines\",\"name\":\"Validation accuracy\",\"x\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],\"y\":[0.5,0.5,0.5,0.5062500238418579,0.5,0.5,0.5,0.5,0.4937500059604645,0.5062500238418579,0.6187499761581421,0.4937500059604645,0.5062500238418579,0.4937500059604645,0.4937500059604645,0.5249999761581421,0.5,0.5,0.543749988079071,0.5],\"type\":\"scatter\",\"xaxis\":\"x\",\"yaxis\":\"y\"},{\"line\":{\"color\":\"red\"},\"mode\":\"lines\",\"name\":\"Training loss\",\"x\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],\"y\":[0.8223278522491455,0.6994679570198059,0.6931896805763245,0.6932819485664368,0.6932724714279175,0.6932827234268188,0.6932427883148193,0.6933978796005249,0.6954671144485474,0.6922488808631897,0.6854684948921204,0.7179708480834961,0.6921708583831787,0.6918408870697021,0.6913188099861145,0.690394937992096,0.6930913925170898,0.6899392604827881,0.692621111869812,0.8392783403396606],\"type\":\"scatter\",\"xaxis\":\"x2\",\"yaxis\":\"y2\"},{\"line\":{\"color\":\"blue\"},\"mode\":\"lines\",\"name\":\"Validation loss\",\"x\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],\"y\":[0.7092774510383606,0.6931637525558472,0.693218469619751,0.6930884122848511,0.6931488513946533,0.6931478381156921,0.6931294798851013,0.6931107044219971,0.704715371131897,0.6980800032615662,0.7779291272163391,0.6935925483703613,0.6930806040763855,0.6932613253593445,0.6932297945022583,0.6911118030548096,0.6931463479995728,0.6929906606674194,0.6859481930732727,0.6931717991828918],\"type\":\"scatter\",\"xaxis\":\"x2\",\"yaxis\":\"y2\"}],                        {\"template\":{\"data\":{\"histogram2dcontour\":[{\"type\":\"histogram2dcontour\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"choropleth\":[{\"type\":\"choropleth\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}],\"histogram2d\":[{\"type\":\"histogram2d\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"heatmap\":[{\"type\":\"heatmap\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"heatmapgl\":[{\"type\":\"heatmapgl\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"contourcarpet\":[{\"type\":\"contourcarpet\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}],\"contour\":[{\"type\":\"contour\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"surface\":[{\"type\":\"surface\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"mesh3d\":[{\"type\":\"mesh3d\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}],\"scatter\":[{\"fillpattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2},\"type\":\"scatter\"}],\"parcoords\":[{\"type\":\"parcoords\",\"line\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatterpolargl\":[{\"type\":\"scatterpolargl\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"bar\":[{\"error_x\":{\"color\":\"#2a3f5f\"},\"error_y\":{\"color\":\"#2a3f5f\"},\"marker\":{\"line\":{\"color\":\"#E5ECF6\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"bar\"}],\"scattergeo\":[{\"type\":\"scattergeo\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatterpolar\":[{\"type\":\"scatterpolar\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"histogram\":[{\"marker\":{\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"histogram\"}],\"scattergl\":[{\"type\":\"scattergl\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatter3d\":[{\"type\":\"scatter3d\",\"line\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scattermapbox\":[{\"type\":\"scattermapbox\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatterternary\":[{\"type\":\"scatterternary\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scattercarpet\":[{\"type\":\"scattercarpet\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"carpet\":[{\"aaxis\":{\"endlinecolor\":\"#2a3f5f\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"minorgridcolor\":\"white\",\"startlinecolor\":\"#2a3f5f\"},\"baxis\":{\"endlinecolor\":\"#2a3f5f\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"minorgridcolor\":\"white\",\"startlinecolor\":\"#2a3f5f\"},\"type\":\"carpet\"}],\"table\":[{\"cells\":{\"fill\":{\"color\":\"#EBF0F8\"},\"line\":{\"color\":\"white\"}},\"header\":{\"fill\":{\"color\":\"#C8D4E3\"},\"line\":{\"color\":\"white\"}},\"type\":\"table\"}],\"barpolar\":[{\"marker\":{\"line\":{\"color\":\"#E5ECF6\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"barpolar\"}],\"pie\":[{\"automargin\":true,\"type\":\"pie\"}]},\"layout\":{\"autotypenumbers\":\"strict\",\"colorway\":[\"#636efa\",\"#EF553B\",\"#00cc96\",\"#ab63fa\",\"#FFA15A\",\"#19d3f3\",\"#FF6692\",\"#B6E880\",\"#FF97FF\",\"#FECB52\"],\"font\":{\"color\":\"#2a3f5f\"},\"hovermode\":\"closest\",\"hoverlabel\":{\"align\":\"left\"},\"paper_bgcolor\":\"white\",\"plot_bgcolor\":\"#E5ECF6\",\"polar\":{\"bgcolor\":\"#E5ECF6\",\"angularaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"},\"radialaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"}},\"ternary\":{\"bgcolor\":\"#E5ECF6\",\"aaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"},\"baxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"},\"caxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"}},\"coloraxis\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"colorscale\":{\"sequential\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"sequentialminus\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"diverging\":[[0,\"#8e0152\"],[0.1,\"#c51b7d\"],[0.2,\"#de77ae\"],[0.3,\"#f1b6da\"],[0.4,\"#fde0ef\"],[0.5,\"#f7f7f7\"],[0.6,\"#e6f5d0\"],[0.7,\"#b8e186\"],[0.8,\"#7fbc41\"],[0.9,\"#4d9221\"],[1,\"#276419\"]]},\"xaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\",\"title\":{\"standoff\":15},\"zerolinecolor\":\"white\",\"automargin\":true,\"zerolinewidth\":2},\"yaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\",\"title\":{\"standoff\":15},\"zerolinecolor\":\"white\",\"automargin\":true,\"zerolinewidth\":2},\"scene\":{\"xaxis\":{\"backgroundcolor\":\"#E5ECF6\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"white\",\"gridwidth\":2},\"yaxis\":{\"backgroundcolor\":\"#E5ECF6\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"white\",\"gridwidth\":2},\"zaxis\":{\"backgroundcolor\":\"#E5ECF6\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"white\",\"gridwidth\":2}},\"shapedefaults\":{\"line\":{\"color\":\"#2a3f5f\"}},\"annotationdefaults\":{\"arrowcolor\":\"#2a3f5f\",\"arrowhead\":0,\"arrowwidth\":1},\"geo\":{\"bgcolor\":\"white\",\"landcolor\":\"#E5ECF6\",\"subunitcolor\":\"white\",\"showland\":true,\"showlakes\":true,\"lakecolor\":\"white\"},\"title\":{\"x\":0.05},\"mapbox\":{\"style\":\"light\"}}},\"xaxis\":{\"anchor\":\"y\",\"domain\":[0.0,0.45],\"title\":{\"text\":\"Epochs\"}},\"yaxis\":{\"anchor\":\"x\",\"domain\":[0.0,1.0],\"title\":{\"text\":\"Accuracy\"}},\"xaxis2\":{\"anchor\":\"y2\",\"domain\":[0.55,1.0],\"title\":{\"text\":\"Epochs\"}},\"yaxis2\":{\"anchor\":\"x2\",\"domain\":[0.0,1.0],\"title\":{\"text\":\"Loss\"}},\"annotations\":[{\"font\":{\"size\":16},\"showarrow\":false,\"text\":\"Accuracy\",\"x\":0.225,\"xanchor\":\"center\",\"xref\":\"paper\",\"y\":1.0,\"yanchor\":\"bottom\",\"yref\":\"paper\"},{\"font\":{\"size\":16},\"showarrow\":false,\"text\":\"Loss\",\"x\":0.775,\"xanchor\":\"center\",\"xref\":\"paper\",\"y\":1.0,\"yanchor\":\"bottom\",\"yref\":\"paper\"}],\"title\":{\"text\":\"Aleksandra's ResNet Model Training and Validation Metrics Over Epochs\",\"x\":0.5}},                        {\"responsive\": true}                    ).then(function(){\n",
              "                            \n",
              "var gd = document.getElementById('e2178ac2-eace-49a1-b596-b6b76dceea3a');\n",
              "var x = new MutationObserver(function (mutations, observer) {{\n",
              "        var display = window.getComputedStyle(gd).display;\n",
              "        if (!display || display === 'none') {{\n",
              "            console.log([gd, 'removed!']);\n",
              "            Plotly.purge(gd);\n",
              "            observer.disconnect();\n",
              "        }}\n",
              "}});\n",
              "\n",
              "// Listen for the removal of the full notebook cells\n",
              "var notebookContainer = gd.closest('#notebook-container');\n",
              "if (notebookContainer) {{\n",
              "    x.observe(notebookContainer, {childList: true});\n",
              "}}\n",
              "\n",
              "// Listen for the clearing of the current output cell\n",
              "var outputEl = gd.closest('.output');\n",
              "if (outputEl) {{\n",
              "    x.observe(outputEl, {childList: true});\n",
              "}}\n",
              "\n",
              "                        })                };                            </script>        </div>\n",
              "</body>\n",
              "</html>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "# VGG16 Model"
      ],
      "metadata": {
        "id": "S1KvoFYkil9F"
      }
    },
    {
      "cell_type": "code",
      "source": [
        "from tensorflow.keras.applications import VGG16\n",
        "\n",
        "# Load the pre-trained VGG16 model without the top classification layer\n",
        "base_model_vgg16 = VGG16(weights='imagenet', include_top=False, input_shape=(img_width, img_height, 3))\n",
        "\n",
        "# Freeze the base model layers\n",
        "for layer in base_model_vgg16.layers:\n",
        "    layer.trainable = False\n",
        "\n",
        "# Add custom classification layers on top of VGG16\n",
        "model_vgg16 = Sequential([\n",
        "    base_model_vgg16,\n",
        "    Flatten(),\n",
        "    Dense(256, activation='relu'),\n",
        "    Dense(1, activation='sigmoid')\n",
        "])\n",
        "\n",
        "# Compile the model\n",
        "model_vgg16.compile(optimizer='adam',\n",
        "                     loss='binary_crossentropy',\n",
        "                     metrics=['accuracy'])\n",
        "\n",
        "# Train the model\n",
        "history_vgg16 = model_vgg16.fit(train_generator,\n",
        "                                steps_per_epoch=train_generator.samples // batch_size,\n",
        "                                epochs=20,\n",
        "                                validation_data=val_generator,\n",
        "                                validation_steps=val_generator.samples // batch_size)\n",
        "\n",
        "# Evaluate the model on the test data\n",
        "test_loss_vgg16, test_accuracy_vgg16 = model_vgg16.evaluate(test_generator, steps=test_generator.samples // batch_size)\n",
        "print(\"Test Accuracy (VGG16):\", test_accuracy_vgg16)\n"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "LOnHXrInfhWM",
        "outputId": "daf144ec-92ba-44e9-d541-5f6976e95d79"
      },
      "execution_count": 40,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Downloading data from https://storage.googleapis.com/tensorflow/keras-applications/vgg16/vgg16_weights_tf_dim_ordering_tf_kernels_notop.h5\n",
            "58889256/58889256 [==============================] - 0s 0us/step\n",
            "Epoch 1/20\n",
            "23/23 [==============================] - 36s 1s/step - loss: 1.1893 - accuracy: 0.6492 - val_loss: 0.7287 - val_accuracy: 0.5938\n",
            "Epoch 2/20\n",
            "23/23 [==============================] - 26s 1s/step - loss: 0.4430 - accuracy: 0.7970 - val_loss: 0.4375 - val_accuracy: 0.8000\n",
            "Epoch 3/20\n",
            "23/23 [==============================] - 26s 1s/step - loss: 0.4050 - accuracy: 0.8191 - val_loss: 0.4244 - val_accuracy: 0.7750\n",
            "Epoch 4/20\n",
            "23/23 [==============================] - 27s 1s/step - loss: 0.3903 - accuracy: 0.8163 - val_loss: 0.4183 - val_accuracy: 0.8000\n",
            "Epoch 5/20\n",
            "23/23 [==============================] - 26s 1s/step - loss: 0.4081 - accuracy: 0.8149 - val_loss: 0.7425 - val_accuracy: 0.6125\n",
            "Epoch 6/20\n",
            "23/23 [==============================] - 25s 1s/step - loss: 0.4108 - accuracy: 0.8149 - val_loss: 0.5616 - val_accuracy: 0.7437\n",
            "Epoch 7/20\n",
            "23/23 [==============================] - 26s 1s/step - loss: 0.4341 - accuracy: 0.8108 - val_loss: 0.4216 - val_accuracy: 0.8062\n",
            "Epoch 8/20\n",
            "23/23 [==============================] - 26s 1s/step - loss: 0.5043 - accuracy: 0.7942 - val_loss: 0.6160 - val_accuracy: 0.7375\n",
            "Epoch 9/20\n",
            "23/23 [==============================] - 26s 1s/step - loss: 0.7987 - accuracy: 0.7210 - val_loss: 0.4747 - val_accuracy: 0.7625\n",
            "Epoch 10/20\n",
            "23/23 [==============================] - 26s 1s/step - loss: 0.4596 - accuracy: 0.8108 - val_loss: 0.4338 - val_accuracy: 0.8062\n",
            "Epoch 11/20\n",
            "23/23 [==============================] - 27s 1s/step - loss: 0.3857 - accuracy: 0.8329 - val_loss: 0.4259 - val_accuracy: 0.8000\n",
            "Epoch 12/20\n",
            "23/23 [==============================] - 27s 1s/step - loss: 0.3696 - accuracy: 0.8398 - val_loss: 0.4199 - val_accuracy: 0.7875\n",
            "Epoch 13/20\n",
            "23/23 [==============================] - 25s 1s/step - loss: 0.4194 - accuracy: 0.8177 - val_loss: 0.4733 - val_accuracy: 0.7375\n",
            "Epoch 14/20\n",
            "23/23 [==============================] - 25s 1s/step - loss: 0.3860 - accuracy: 0.8301 - val_loss: 0.4263 - val_accuracy: 0.8188\n",
            "Epoch 15/20\n",
            "23/23 [==============================] - 26s 1s/step - loss: 0.3533 - accuracy: 0.8287 - val_loss: 0.6372 - val_accuracy: 0.7375\n",
            "Epoch 16/20\n",
            "23/23 [==============================] - 26s 1s/step - loss: 0.4375 - accuracy: 0.8135 - val_loss: 0.5326 - val_accuracy: 0.7812\n",
            "Epoch 17/20\n",
            "23/23 [==============================] - 26s 1s/step - loss: 0.3617 - accuracy: 0.8343 - val_loss: 0.4070 - val_accuracy: 0.7812\n",
            "Epoch 18/20\n",
            "23/23 [==============================] - 25s 1s/step - loss: 0.3729 - accuracy: 0.8398 - val_loss: 0.4152 - val_accuracy: 0.7875\n",
            "Epoch 19/20\n",
            "23/23 [==============================] - 26s 1s/step - loss: 0.3068 - accuracy: 0.8702 - val_loss: 0.4287 - val_accuracy: 0.7750\n",
            "Epoch 20/20\n",
            "23/23 [==============================] - 26s 1s/step - loss: 0.3518 - accuracy: 0.8329 - val_loss: 0.4163 - val_accuracy: 0.8313\n",
            "5/5 [==============================] - 3s 621ms/step - loss: 0.3400 - accuracy: 0.8500\n",
            "Test Accuracy (VGG16): 0.8500000238418579\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# Extracting training and validation metrics from history object\n",
        "train_accuracy_vgg16 = history_vgg16.history['accuracy']\n",
        "val_accuracy_vgg16 = history_vgg16.history['val_accuracy']\n",
        "train_loss_vgg16 = history_vgg16.history['loss']\n",
        "val_loss_vgg16 = history_vgg16.history['val_loss']\n",
        "\n",
        "# Extracting epochs\n",
        "epochs_list_vgg16 = list(range(1, len(train_accuracy_vgg16) + 1))\n",
        "\n",
        "# Define colors for training and validation lines\n",
        "train_color = 'red'\n",
        "val_color = 'blue'\n",
        "\n",
        "# Create subplots\n",
        "fig = make_subplots(rows=1, cols=2, subplot_titles=(\"Accuracy (VGG16)\", \"Loss (VGG16)\"))\n",
        "\n",
        "# Add traces for accuracy\n",
        "fig.add_trace(go.Scatter(x=epochs_list_vgg16, y=train_accuracy_vgg16, mode='lines', name='Training accuracy', line=dict(color=train_color)), row=1, col=1)\n",
        "fig.add_trace(go.Scatter(x=epochs_list_vgg16, y=val_accuracy_vgg16, mode='lines', name='Validation accuracy', line=dict(color=val_color)), row=1, col=1)\n",
        "\n",
        "# Add traces for loss\n",
        "fig.add_trace(go.Scatter(x=epochs_list_vgg16, y=train_loss_vgg16, mode='lines', name='Training loss', line=dict(color=train_color)), row=1, col=2)\n",
        "fig.add_trace(go.Scatter(x=epochs_list_vgg16, y=val_loss_vgg16, mode='lines', name='Validation loss', line=dict(color=val_color)), row=1, col=2)\n",
        "\n",
        "# Update layout\n",
        "fig.update_layout(title_text=\"VGG16 Training and Validation Metrics Over Epochs\", title_x=0.5)\n",
        "fig.update_xaxes(title_text=\"Epochs\", row=1, col=1)\n",
        "fig.update_xaxes(title_text=\"Epochs\", row=1, col=2)\n",
        "fig.update_yaxes(title_text=\"Accuracy\", row=1, col=1)\n",
        "fig.update_yaxes(title_text=\"Loss\", row=1, col=2)\n",
        "\n",
        "# Show plot\n",
        "fig.show()\n"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 542
        },
        "id": "PWork6b_icy0",
        "outputId": "53e199b2-85a2-4f21-a08f-0093bf467149"
      },
      "execution_count": 41,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<html>\n",
              "<head><meta charset=\"utf-8\" /></head>\n",
              "<body>\n",
              "    <div>            <script src=\"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_SVG\"></script><script type=\"text/javascript\">if (window.MathJax && window.MathJax.Hub && window.MathJax.Hub.Config) {window.MathJax.Hub.Config({SVG: {font: \"STIX-Web\"}});}</script>                <script type=\"text/javascript\">window.PlotlyConfig = {MathJaxConfig: 'local'};</script>\n",
              "        <script charset=\"utf-8\" src=\"https://cdn.plot.ly/plotly-2.24.1.min.js\"></script>                <div id=\"2c93fa27-61d1-423a-9c11-4643d2b57d91\" class=\"plotly-graph-div\" style=\"height:525px; width:100%;\"></div>            <script type=\"text/javascript\">                                    window.PLOTLYENV=window.PLOTLYENV || {};                                    if (document.getElementById(\"2c93fa27-61d1-423a-9c11-4643d2b57d91\")) {                    Plotly.newPlot(                        \"2c93fa27-61d1-423a-9c11-4643d2b57d91\",                        [{\"line\":{\"color\":\"red\"},\"mode\":\"lines\",\"name\":\"Training accuracy\",\"x\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],\"y\":[0.6491712927818298,0.7969613075256348,0.8190608024597168,0.8162983655929565,0.8149171471595764,0.8149171471595764,0.810773491859436,0.7941988706588745,0.7209944725036621,0.810773491859436,0.8328729271888733,0.8397790193557739,0.8176795840263367,0.830110490322113,0.8287292718887329,0.8135359287261963,0.8342541456222534,0.8397790193557739,0.8701657652854919,0.8328729271888733],\"type\":\"scatter\",\"xaxis\":\"x\",\"yaxis\":\"y\"},{\"line\":{\"color\":\"blue\"},\"mode\":\"lines\",\"name\":\"Validation accuracy\",\"x\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],\"y\":[0.59375,0.800000011920929,0.7749999761581421,0.800000011920929,0.612500011920929,0.7437499761581421,0.8062499761581421,0.737500011920929,0.762499988079071,0.8062499761581421,0.800000011920929,0.7875000238418579,0.737500011920929,0.8187500238418579,0.737500011920929,0.78125,0.78125,0.7875000238418579,0.7749999761581421,0.831250011920929],\"type\":\"scatter\",\"xaxis\":\"x\",\"yaxis\":\"y\"},{\"line\":{\"color\":\"red\"},\"mode\":\"lines\",\"name\":\"Training loss\",\"x\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],\"y\":[1.189307689666748,0.44295167922973633,0.40499189496040344,0.3903469741344452,0.4080970585346222,0.4107876718044281,0.4341225326061249,0.5042685866355896,0.7987245321273804,0.4596422016620636,0.38566792011260986,0.3695501685142517,0.41936784982681274,0.38597923517227173,0.35331809520721436,0.4375077188014984,0.3616504967212677,0.37288641929626465,0.3068265914916992,0.3518027067184448],\"type\":\"scatter\",\"xaxis\":\"x2\",\"yaxis\":\"y2\"},{\"line\":{\"color\":\"blue\"},\"mode\":\"lines\",\"name\":\"Validation loss\",\"x\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20],\"y\":[0.7286972403526306,0.4375019073486328,0.42444711923599243,0.41833382844924927,0.7424896955490112,0.5615683794021606,0.42155736684799194,0.6159632205963135,0.4747372269630432,0.433795303106308,0.42590951919555664,0.4199264645576477,0.4733251929283142,0.42631053924560547,0.6371903419494629,0.532568097114563,0.40695151686668396,0.4151891767978668,0.42865151166915894,0.4162680506706238],\"type\":\"scatter\",\"xaxis\":\"x2\",\"yaxis\":\"y2\"}],                        {\"template\":{\"data\":{\"histogram2dcontour\":[{\"type\":\"histogram2dcontour\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"choropleth\":[{\"type\":\"choropleth\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}],\"histogram2d\":[{\"type\":\"histogram2d\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"heatmap\":[{\"type\":\"heatmap\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"heatmapgl\":[{\"type\":\"heatmapgl\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"contourcarpet\":[{\"type\":\"contourcarpet\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}],\"contour\":[{\"type\":\"contour\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"surface\":[{\"type\":\"surface\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"mesh3d\":[{\"type\":\"mesh3d\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}],\"scatter\":[{\"fillpattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2},\"type\":\"scatter\"}],\"parcoords\":[{\"type\":\"parcoords\",\"line\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatterpolargl\":[{\"type\":\"scatterpolargl\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"bar\":[{\"error_x\":{\"color\":\"#2a3f5f\"},\"error_y\":{\"color\":\"#2a3f5f\"},\"marker\":{\"line\":{\"color\":\"#E5ECF6\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"bar\"}],\"scattergeo\":[{\"type\":\"scattergeo\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatterpolar\":[{\"type\":\"scatterpolar\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"histogram\":[{\"marker\":{\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"histogram\"}],\"scattergl\":[{\"type\":\"scattergl\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatter3d\":[{\"type\":\"scatter3d\",\"line\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scattermapbox\":[{\"type\":\"scattermapbox\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatterternary\":[{\"type\":\"scatterternary\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scattercarpet\":[{\"type\":\"scattercarpet\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"carpet\":[{\"aaxis\":{\"endlinecolor\":\"#2a3f5f\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"minorgridcolor\":\"white\",\"startlinecolor\":\"#2a3f5f\"},\"baxis\":{\"endlinecolor\":\"#2a3f5f\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"minorgridcolor\":\"white\",\"startlinecolor\":\"#2a3f5f\"},\"type\":\"carpet\"}],\"table\":[{\"cells\":{\"fill\":{\"color\":\"#EBF0F8\"},\"line\":{\"color\":\"white\"}},\"header\":{\"fill\":{\"color\":\"#C8D4E3\"},\"line\":{\"color\":\"white\"}},\"type\":\"table\"}],\"barpolar\":[{\"marker\":{\"line\":{\"color\":\"#E5ECF6\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"barpolar\"}],\"pie\":[{\"automargin\":true,\"type\":\"pie\"}]},\"layout\":{\"autotypenumbers\":\"strict\",\"colorway\":[\"#636efa\",\"#EF553B\",\"#00cc96\",\"#ab63fa\",\"#FFA15A\",\"#19d3f3\",\"#FF6692\",\"#B6E880\",\"#FF97FF\",\"#FECB52\"],\"font\":{\"color\":\"#2a3f5f\"},\"hovermode\":\"closest\",\"hoverlabel\":{\"align\":\"left\"},\"paper_bgcolor\":\"white\",\"plot_bgcolor\":\"#E5ECF6\",\"polar\":{\"bgcolor\":\"#E5ECF6\",\"angularaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"},\"radialaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"}},\"ternary\":{\"bgcolor\":\"#E5ECF6\",\"aaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"},\"baxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"},\"caxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"}},\"coloraxis\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"colorscale\":{\"sequential\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"sequentialminus\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"diverging\":[[0,\"#8e0152\"],[0.1,\"#c51b7d\"],[0.2,\"#de77ae\"],[0.3,\"#f1b6da\"],[0.4,\"#fde0ef\"],[0.5,\"#f7f7f7\"],[0.6,\"#e6f5d0\"],[0.7,\"#b8e186\"],[0.8,\"#7fbc41\"],[0.9,\"#4d9221\"],[1,\"#276419\"]]},\"xaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\",\"title\":{\"standoff\":15},\"zerolinecolor\":\"white\",\"automargin\":true,\"zerolinewidth\":2},\"yaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\",\"title\":{\"standoff\":15},\"zerolinecolor\":\"white\",\"automargin\":true,\"zerolinewidth\":2},\"scene\":{\"xaxis\":{\"backgroundcolor\":\"#E5ECF6\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"white\",\"gridwidth\":2},\"yaxis\":{\"backgroundcolor\":\"#E5ECF6\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"white\",\"gridwidth\":2},\"zaxis\":{\"backgroundcolor\":\"#E5ECF6\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"white\",\"gridwidth\":2}},\"shapedefaults\":{\"line\":{\"color\":\"#2a3f5f\"}},\"annotationdefaults\":{\"arrowcolor\":\"#2a3f5f\",\"arrowhead\":0,\"arrowwidth\":1},\"geo\":{\"bgcolor\":\"white\",\"landcolor\":\"#E5ECF6\",\"subunitcolor\":\"white\",\"showland\":true,\"showlakes\":true,\"lakecolor\":\"white\"},\"title\":{\"x\":0.05},\"mapbox\":{\"style\":\"light\"}}},\"xaxis\":{\"anchor\":\"y\",\"domain\":[0.0,0.45],\"title\":{\"text\":\"Epochs\"}},\"yaxis\":{\"anchor\":\"x\",\"domain\":[0.0,1.0],\"title\":{\"text\":\"Accuracy\"}},\"xaxis2\":{\"anchor\":\"y2\",\"domain\":[0.55,1.0],\"title\":{\"text\":\"Epochs\"}},\"yaxis2\":{\"anchor\":\"x2\",\"domain\":[0.0,1.0],\"title\":{\"text\":\"Loss\"}},\"annotations\":[{\"font\":{\"size\":16},\"showarrow\":false,\"text\":\"Accuracy (VGG16)\",\"x\":0.225,\"xanchor\":\"center\",\"xref\":\"paper\",\"y\":1.0,\"yanchor\":\"bottom\",\"yref\":\"paper\"},{\"font\":{\"size\":16},\"showarrow\":false,\"text\":\"Loss (VGG16)\",\"x\":0.775,\"xanchor\":\"center\",\"xref\":\"paper\",\"y\":1.0,\"yanchor\":\"bottom\",\"yref\":\"paper\"}],\"title\":{\"text\":\"VGG16 Training and Validation Metrics Over Epochs\",\"x\":0.5}},                        {\"responsive\": true}                    ).then(function(){\n",
              "                            \n",
              "var gd = document.getElementById('2c93fa27-61d1-423a-9c11-4643d2b57d91');\n",
              "var x = new MutationObserver(function (mutations, observer) {{\n",
              "        var display = window.getComputedStyle(gd).display;\n",
              "        if (!display || display === 'none') {{\n",
              "            console.log([gd, 'removed!']);\n",
              "            Plotly.purge(gd);\n",
              "            observer.disconnect();\n",
              "        }}\n",
              "}});\n",
              "\n",
              "// Listen for the removal of the full notebook cells\n",
              "var notebookContainer = gd.closest('#notebook-container');\n",
              "if (notebookContainer) {{\n",
              "    x.observe(notebookContainer, {childList: true});\n",
              "}}\n",
              "\n",
              "// Listen for the clearing of the current output cell\n",
              "var outputEl = gd.closest('.output');\n",
              "if (outputEl) {{\n",
              "    x.observe(outputEl, {childList: true});\n",
              "}}\n",
              "\n",
              "                        })                };                            </script>        </div>\n",
              "</body>\n",
              "</html>"
            ]
          },
          "metadata": {}
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "# Define model names\n",
        "model_names = [\"ResNet50\", \"ResNet100\", \"ResNet\", \"VGG16\"]\n",
        "\n",
        "# Define test accuracies\n",
        "test_accuracies = [test_accuracy, test_accuracy100, test_accuracy_mine, test_accuracy_vgg16]\n",
        "\n",
        "# Create bar plot\n",
        "fig = go.Figure(data=[go.Bar(x=model_names, y=test_accuracies, marker_color='skyblue')])\n",
        "fig.update_layout(title='Comparison of Test Accuracies for Different Models',\n",
        "                  xaxis_title='Model',\n",
        "                  yaxis_title='Test Accuracy',\n",
        "                  xaxis_tickangle=-45)\n",
        "fig.show()"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 542
        },
        "id": "zIH5ddGZn_a-",
        "outputId": "7e7c24ac-d43e-40d1-ea00-d41b436d2666"
      },
      "execution_count": 52,
      "outputs": [
        {
          "output_type": "display_data",
          "data": {
            "text/html": [
              "<html>\n",
              "<head><meta charset=\"utf-8\" /></head>\n",
              "<body>\n",
              "    <div>            <script src=\"https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_SVG\"></script><script type=\"text/javascript\">if (window.MathJax && window.MathJax.Hub && window.MathJax.Hub.Config) {window.MathJax.Hub.Config({SVG: {font: \"STIX-Web\"}});}</script>                <script type=\"text/javascript\">window.PlotlyConfig = {MathJaxConfig: 'local'};</script>\n",
              "        <script charset=\"utf-8\" src=\"https://cdn.plot.ly/plotly-2.24.1.min.js\"></script>                <div id=\"74fecef3-47db-431a-a626-f3053b4ff5ba\" class=\"plotly-graph-div\" style=\"height:525px; width:100%;\"></div>            <script type=\"text/javascript\">                                    window.PLOTLYENV=window.PLOTLYENV || {};                                    if (document.getElementById(\"74fecef3-47db-431a-a626-f3053b4ff5ba\")) {                    Plotly.newPlot(                        \"74fecef3-47db-431a-a626-f3053b4ff5ba\",                        [{\"marker\":{\"color\":\"skyblue\"},\"x\":[\"ResNet50\",\"ResNet100\",\"ResNet\",\"VGG16\"],\"y\":[0.512499988079071,0.699999988079071,0.8187500238418579,0.8500000238418579],\"type\":\"bar\"}],                        {\"template\":{\"data\":{\"histogram2dcontour\":[{\"type\":\"histogram2dcontour\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"choropleth\":[{\"type\":\"choropleth\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}],\"histogram2d\":[{\"type\":\"histogram2d\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"heatmap\":[{\"type\":\"heatmap\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"heatmapgl\":[{\"type\":\"heatmapgl\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"contourcarpet\":[{\"type\":\"contourcarpet\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}],\"contour\":[{\"type\":\"contour\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"surface\":[{\"type\":\"surface\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"},\"colorscale\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]]}],\"mesh3d\":[{\"type\":\"mesh3d\",\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}],\"scatter\":[{\"fillpattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2},\"type\":\"scatter\"}],\"parcoords\":[{\"type\":\"parcoords\",\"line\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatterpolargl\":[{\"type\":\"scatterpolargl\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"bar\":[{\"error_x\":{\"color\":\"#2a3f5f\"},\"error_y\":{\"color\":\"#2a3f5f\"},\"marker\":{\"line\":{\"color\":\"#E5ECF6\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"bar\"}],\"scattergeo\":[{\"type\":\"scattergeo\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatterpolar\":[{\"type\":\"scatterpolar\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"histogram\":[{\"marker\":{\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"histogram\"}],\"scattergl\":[{\"type\":\"scattergl\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatter3d\":[{\"type\":\"scatter3d\",\"line\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scattermapbox\":[{\"type\":\"scattermapbox\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scatterternary\":[{\"type\":\"scatterternary\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"scattercarpet\":[{\"type\":\"scattercarpet\",\"marker\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}}}],\"carpet\":[{\"aaxis\":{\"endlinecolor\":\"#2a3f5f\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"minorgridcolor\":\"white\",\"startlinecolor\":\"#2a3f5f\"},\"baxis\":{\"endlinecolor\":\"#2a3f5f\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"minorgridcolor\":\"white\",\"startlinecolor\":\"#2a3f5f\"},\"type\":\"carpet\"}],\"table\":[{\"cells\":{\"fill\":{\"color\":\"#EBF0F8\"},\"line\":{\"color\":\"white\"}},\"header\":{\"fill\":{\"color\":\"#C8D4E3\"},\"line\":{\"color\":\"white\"}},\"type\":\"table\"}],\"barpolar\":[{\"marker\":{\"line\":{\"color\":\"#E5ECF6\",\"width\":0.5},\"pattern\":{\"fillmode\":\"overlay\",\"size\":10,\"solidity\":0.2}},\"type\":\"barpolar\"}],\"pie\":[{\"automargin\":true,\"type\":\"pie\"}]},\"layout\":{\"autotypenumbers\":\"strict\",\"colorway\":[\"#636efa\",\"#EF553B\",\"#00cc96\",\"#ab63fa\",\"#FFA15A\",\"#19d3f3\",\"#FF6692\",\"#B6E880\",\"#FF97FF\",\"#FECB52\"],\"font\":{\"color\":\"#2a3f5f\"},\"hovermode\":\"closest\",\"hoverlabel\":{\"align\":\"left\"},\"paper_bgcolor\":\"white\",\"plot_bgcolor\":\"#E5ECF6\",\"polar\":{\"bgcolor\":\"#E5ECF6\",\"angularaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"},\"radialaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"}},\"ternary\":{\"bgcolor\":\"#E5ECF6\",\"aaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"},\"baxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"},\"caxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\"}},\"coloraxis\":{\"colorbar\":{\"outlinewidth\":0,\"ticks\":\"\"}},\"colorscale\":{\"sequential\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"sequentialminus\":[[0.0,\"#0d0887\"],[0.1111111111111111,\"#46039f\"],[0.2222222222222222,\"#7201a8\"],[0.3333333333333333,\"#9c179e\"],[0.4444444444444444,\"#bd3786\"],[0.5555555555555556,\"#d8576b\"],[0.6666666666666666,\"#ed7953\"],[0.7777777777777778,\"#fb9f3a\"],[0.8888888888888888,\"#fdca26\"],[1.0,\"#f0f921\"]],\"diverging\":[[0,\"#8e0152\"],[0.1,\"#c51b7d\"],[0.2,\"#de77ae\"],[0.3,\"#f1b6da\"],[0.4,\"#fde0ef\"],[0.5,\"#f7f7f7\"],[0.6,\"#e6f5d0\"],[0.7,\"#b8e186\"],[0.8,\"#7fbc41\"],[0.9,\"#4d9221\"],[1,\"#276419\"]]},\"xaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\",\"title\":{\"standoff\":15},\"zerolinecolor\":\"white\",\"automargin\":true,\"zerolinewidth\":2},\"yaxis\":{\"gridcolor\":\"white\",\"linecolor\":\"white\",\"ticks\":\"\",\"title\":{\"standoff\":15},\"zerolinecolor\":\"white\",\"automargin\":true,\"zerolinewidth\":2},\"scene\":{\"xaxis\":{\"backgroundcolor\":\"#E5ECF6\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"white\",\"gridwidth\":2},\"yaxis\":{\"backgroundcolor\":\"#E5ECF6\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"white\",\"gridwidth\":2},\"zaxis\":{\"backgroundcolor\":\"#E5ECF6\",\"gridcolor\":\"white\",\"linecolor\":\"white\",\"showbackground\":true,\"ticks\":\"\",\"zerolinecolor\":\"white\",\"gridwidth\":2}},\"shapedefaults\":{\"line\":{\"color\":\"#2a3f5f\"}},\"annotationdefaults\":{\"arrowcolor\":\"#2a3f5f\",\"arrowhead\":0,\"arrowwidth\":1},\"geo\":{\"bgcolor\":\"white\",\"landcolor\":\"#E5ECF6\",\"subunitcolor\":\"white\",\"showland\":true,\"showlakes\":true,\"lakecolor\":\"white\"},\"title\":{\"x\":0.05},\"mapbox\":{\"style\":\"light\"}}},\"xaxis\":{\"title\":{\"text\":\"Model\"},\"tickangle\":-45},\"title\":{\"text\":\"Comparison of Test Accuracies for Different Models\"},\"yaxis\":{\"title\":{\"text\":\"Test Accuracy\"}}},                        {\"responsive\": true}                    ).then(function(){\n",
              "                            \n",
              "var gd = document.getElementById('74fecef3-47db-431a-a626-f3053b4ff5ba');\n",
              "var x = new MutationObserver(function (mutations, observer) {{\n",
              "        var display = window.getComputedStyle(gd).display;\n",
              "        if (!display || display === 'none') {{\n",
              "            console.log([gd, 'removed!']);\n",
              "            Plotly.purge(gd);\n",
              "            observer.disconnect();\n",
              "        }}\n",
              "}});\n",
              "\n",
              "// Listen for the removal of the full notebook cells\n",
              "var notebookContainer = gd.closest('#notebook-container');\n",
              "if (notebookContainer) {{\n",
              "    x.observe(notebookContainer, {childList: true});\n",
              "}}\n",
              "\n",
              "// Listen for the clearing of the current output cell\n",
              "var outputEl = gd.closest('.output');\n",
              "if (outputEl) {{\n",
              "    x.observe(outputEl, {childList: true});\n",
              "}}\n",
              "\n",
              "                        })                };                            </script>        </div>\n",
              "</body>\n",
              "</html>"
            ]
          },
          "metadata": {}
        }
      ]
    }
  ]
}